package cn.fl.project.controller;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.user.facade.system.api.IPriorityApiService;
import cmm.user.facade.system.dto.SysResourceDTO;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.utils.*;
import cn.cmm.cache.framework.utils.PropertiesCacheUtils;
import cn.fl.capital.condition.CapBindLogQC;
import cn.fl.capital.condition.CapFeeOutLogQueryCondition;
import cn.fl.capital.condition.CapOverdueInfoQueryCondition;
import cn.fl.capital.condition.CapPayInfoQueryCondition;
import cn.fl.capital.constant.CapPayInfoConstant;
import cn.fl.capital.service.*;
import cn.fl.capital.vo.*;
import cn.fl.commons.result.ResponseData;
import cn.fl.customer.service.ICstBscInfoService;
import cn.fl.customer.vo.CstBscInfoVO;
import cn.fl.dk.facade.constant.PrdStsCdConstant;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.insurance.condition.InsFeeDeductRecQueryCondition;
import cn.fl.insurance.constant.InsFeeDeductRecConstant;
import cn.fl.insurance.constant.InsuranceConstant;
import cn.fl.insurance.service.IInsFeeDeductRecService;
import cn.fl.insurance.vo.InsFeeDeductRecVO;
import cn.fl.preloan.dto.financialinterface.DeductLog;
import cn.fl.preloan.dto.financialinterface.QueryWithholdRecordRequest;
import cn.fl.preloan.dto.financialinterface.QueryWithholdRecordResultDTO;
import cn.fl.preloan.enums.PreloanResultCodeEnum;
import cn.fl.preloan.financialinterface.IFinancialService;
import cn.fl.project.ProjectUtils;
import cn.fl.project.condition.*;
import cn.fl.project.constant.*;
import cn.fl.project.dto.PrjPrdPaySchTagDTO;
import cn.fl.project.service.*;
import cn.fl.project.vo.*;
import cn.fl.ref.fncprjbscinfo.service.IFncPrjBscInfoService;
import cn.fl.ref.fncprjbscinfo.vo.FncPrjBscInfoVO;
import cn.fl.ref.fribaseinfo.utils.FundRasInsNmChangeUtil;
import cn.fl.ref.fribaseinfo.vo.FriBaseInfoVO;
import cn.fl.risknew.service.IRiskOverdueService;
import cn.fl.system.constant.SysLogConstant;
import cn.fl.system.service.ISysUlFilesRecService;
import cn.fl.system.vo.SysDictionaryVO;
import cn.fl.system.vo.SysUlFilesRecVO;
import cn.fl.upload.constant.UploadConstant;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.itextpdf.text.Document;
import fl.flow.facade.flow.api.IFlowQueryApiService;
import fl.flow.facade.flow.condition.SysFlowSHQueryCondition;
import fl.flow.facade.flow.constant.FlowConstant;
import fl.flow.facade.flow.dto.SysFlowSHDTO;
import net.sf.json.JSONArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Description: 项目产品支付表主信息表 控制层
 */
@Controller
@RequestMapping("/project/prjprdpayschm")
public class PrjPrdPaySchMController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(PrjPrdPaySchMController.class);
    @Autowired
    private IRiskOverdueService overdueService;
    /**
     * PrjPrdPaySchM 服务层BEAN
     */
    @Autowired
    private IPrjPrdPaySchMService prjPrdPaySchMService;
    /**
     * PrjPrdPaySchM 服务层BEAN
     */
    @Autowired
    private IPrjPrdDtlService prjPrdDtlService;

    @Autowired
    private IPrjPrdPaySchTMService prjPrdPaySchTMService;

    /**
     * 数据字典 服务层BEAN
     */
    @Autowired
    private IPrjQuatPrpsCfgMService prjQuatPrpsCfgMService;
    /**
     * 项目基础服务
     */
    @Autowired
    private IPrjBscInfoService prjBscInfoService;
    /**
     * 项目产品基础服务
     */
    @Autowired
    private IPrjPrdBscInfoService prjPrdBscInfoService;
    /**
     * 项目项目
     */
    @Autowired
    private IPrjQuatPrpsService prjQuatPrpsService;

    /**
     * 项目项目CAP_OVERDUE_INFO
     */
    @Autowired
    private ICapOverdueInfoService capOverdueInfoService;
    /**
     * 客户
     */
    @Autowired
    private ICstBscInfoService cstBscInfoService;

    /**
     * PrjPrdPaySchD 服务层BEAN
     */
    @Autowired
    private IPrjPrdPaySchDService prjPrdPaySchDService;
    @Autowired
    private ICapPayInfoService capPayInfoService;
    @Autowired
    private IPrjPrdDtlTkService prjPrdDtlTkService;
    @Autowired
    private ICapFeeOutLogService capFeeOutLogService;
    @Autowired
    private IFlowQueryApiService flowQueryApiService;
    @Autowired
    private IPrjStlMService prjStlMService;
    /**
     * PrjPrdPaySchD 服务层BEAN
     */
    @Autowired
    private IPrjPrdPaySchTDService prjPrdPaySchTDService;
    /**
     * 保险违约金
     */
    @Autowired
    private IInsFeeDeductRecService insFeeDeductRecService;

    @Autowired
    private ISysUlFilesRecService sysUlFilesRecService;
    @Autowired
    private IPrjPaySchSplmtService prjPaySchSplmtService;

    @Autowired
    private ICapBindLogService capBindLogService;
    @Autowired
    private ICapFundService capFundService;

    @Autowired
    private IPrjMfrPrdPaySchMService prjMfrPrdPaySchMService;

    @Autowired
    private IFncPrjBscInfoService fncPrjBscInfoService; //再融资项目

    /**
     * 数据字典本地服务
     */
    @Autowired
    private ISysDictionaryApiService sysDictionaryApiService;

    /**
     * 权限暴露服务
     */
    @Autowired
    private IPriorityApiService priorityApiService;

    /**
     * 支付表标签暴露服务
     */
    @Autowired
    private IPrjPrdPaySchTagApiService prjPrdPaySchTagApiService;

    @Autowired
    private IFinancialService financialService;

    /**
     * 修改结清数据
     */
    @RequestMapping(value = "/toPayStlDataAddPage.do", method = {RequestMethod.GET})
    public ModelAndView toPayStlDataAddPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toPayStlDataAddPage", "加载PrjPrdPaySchM列表页面.", CurrentThreadContext.getCurrentUserName());
        String id = request.getParameter("id");
        String dtlId = request.getParameter("dtlId");//产品明细
        String prjId = request.getParameter("prjId");//项目id
        List<KeyValueVO> prdStsCdList = this.prjPrdPaySchMService.selectPrjPrdStatusList();
        ModelAndView mav = new ModelAndView("project/prjpayschm/payStlDataPage");
        List<SysDictionaryVO> settFeeTypCdListJSON = this.prjPrdPaySchMService.getSettFeeTypList();
        List<KeyValueVO> yesNoCdList = this.prjQuatPrpsCfgMService.searchYesOrNoCdList();
        mav.addObject("settFeeTypCdListJSON", JSON.toJSONString(settFeeTypCdListJSON));
        mav.addObject("id", id);
        mav.addObject("dtlId", dtlId);
        mav.addObject("prjId", prjId);
        mav.addObject("yesOrNoCdListJSON", JSON.toJSONString(yesNoCdList));
        mav.addObject("prdStsCdList", prdStsCdList);
        return mav;
    }

    /**
     * 添加风险保证金
     */
    @RequestMapping(value = "/toAddRickDepPage.do", method = {RequestMethod.GET})
    public ModelAndView toAddRickDepPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toListPage", "加载PrjPrdPaySchM列表页面.", CurrentThreadContext.getCurrentUserName());
        String id = request.getParameter("id");
        ModelAndView mav = new ModelAndView("project/prjprdquatprps/prjPrdPayRickDepPage");
        mav.addObject("id", id);
        return mav;
    }

    /**
     * 查看风险保证金
     */
    @RequestMapping(value = "/toRickDepDetailPage.do", method = {RequestMethod.GET})
    public ModelAndView toRickDepDetailPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toListPage", "加载PrjPrdPaySchM列表页面.", CurrentThreadContext.getCurrentUserName());
        String id = request.getParameter("id");
        ModelAndView mav = new ModelAndView("project/prjprdquatprps/prjPrdPayRickDepDetailPage");
        PrjPrdPaySchDVO prdPaySchDVO = null;
        PrjPrdPaySchMVO prdPaySchMVO = null;
        PrjBscInfoVO prjBscInfoVO = null;
        String payStsCd = "未付款";
        if (StringUtils.isNotBlank(id)) {
            //支付表明细ID
            prdPaySchDVO = this.prjPrdPaySchDService.selectById(Long.valueOf(id));

            if (null != prdPaySchDVO) {
                //设置元to分
                prdPaySchDVO.setFeeAmt(DecimalUtils.convertFenToYuan(prdPaySchDVO.getFeeAmt().longValue()));
                //支付表主表
                prdPaySchMVO = this.prjPrdPaySchMService.selectById(prdPaySchDVO.getPaySchId());
                prjBscInfoVO = this.prjBscInfoService.selectById(prdPaySchMVO.getPrjId());
                CapPayInfoQueryCondition qc = new CapPayInfoQueryCondition();
                qc.setPaySchId(prdPaySchMVO.getId());
                List<CapPayInfoVO> list = capPayInfoService.searchList(qc);
                if (CollectionUtils.isNotEmpty(list)) {
                    CapPayInfoVO capPayInfoVO = list.get(0);
                    if (capPayInfoVO.getPayStsCd().equals(CapPayInfoConstant.CODE_PAY_STS_CD_FIN)) {
                        payStsCd = "已放款";
                    }
                }
            }

        }
        mav.addObject("prdPaySchDVO", prdPaySchDVO);
        mav.addObject("prdPaySchMVO", prdPaySchMVO);
        mav.addObject("prjBscInfoVO", prjBscInfoVO);
        mav.addObject("payStsCd", payStsCd);
        return mav;
    }

    /**
     * 到列表页面
     */
    @RequestMapping(value = "/toListPage.do", method = {RequestMethod.GET})
    public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toListPage", "加载PrjPrdPaySchM列表页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView mav = new ModelAndView("project/prjpayschm/prjPrdPaySchMList");
        mav.addObject("contractNo",request.getParameter("contractNo"));
        //融资外部机构专用
        mav.addObject("pianflag",request.getParameter("pianflag"));
        mav.addObject("prjId",request.getParameter("prjId"));
        return mav;
    }

    /**
     * 到呈报人驳回页面
     */
    @RequestMapping(value = "/toRejectPage.do", method = {RequestMethod.GET})
    public ModelAndView toRejectPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toRejectPage", "加载toRejectPage列表页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView view = new ModelAndView("project/prjprdquatprps/rejectPage");
        String prjPaySchFeeId = request.getParameter("id");
        PrjPrdPaySchDVO prdPaySchDVO = null;
        PrjPrdPaySchMVO prdPaySchMVO = null;
        PrjBscInfoVO prjBscInfoVO = null;
        String payStsCd = "未付款";
        if (StringUtils.isNotBlank(prjPaySchFeeId)) {
            //支付表明细ID
            prdPaySchDVO = this.prjPrdPaySchDService.selectById(Long.valueOf(prjPaySchFeeId));
            if (null != prdPaySchDVO) {
                //设置元to分
                prdPaySchDVO.setFeeAmt(DecimalUtils.convertFenToYuan(prdPaySchDVO.getFeeAmt().longValue()));
                //支付表主表
                prdPaySchMVO = this.prjPrdPaySchMService.selectById(prdPaySchDVO.getPaySchId());
                prjBscInfoVO = this.prjBscInfoService.selectById(prdPaySchMVO.getPrjId());
                CapPayInfoQueryCondition qc = new CapPayInfoQueryCondition();
                qc.setPaySchId(prdPaySchMVO.getId());
                List<CapPayInfoVO> list = capPayInfoService.searchList(qc);
                if (CollectionUtils.isNotEmpty(list)) {
                    CapPayInfoVO capPayInfoVO = list.get(0);
                    if (capPayInfoVO.getPayStsCd().equals(CapPayInfoConstant.CODE_PAY_STS_CD_FIN)) {
                        payStsCd = "已放款";
                    }
                }
            }

        }
        view.addObject("prdPaySchDVO", prdPaySchDVO);
        view.addObject("prdPaySchMVO", prdPaySchMVO);
        view.addObject("prjBscInfoVO", prjBscInfoVO);
        view.addObject("prjPaySchFeeId", prjPaySchFeeId);
        view.addObject("payStsCd", payStsCd);
        return view;
    }

    /**
     * 初始化补充信息页面
     */
    @RequestMapping(value = "/rejectPageInitList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object rejectPageInitList(HttpServletRequest request, HttpServletResponse response) {
        String prjPaySchFeeId = request.getParameter("prjPaySchFeeId");
        List<PrjPaySchSplmtVO> qcList = null;
        if (StringUtils.isNotBlank(prjPaySchFeeId)) {
            PrjPaySchSplmtQC qc = new PrjPaySchSplmtQC();
            qc.setPrjPaySchFeeId(Long.valueOf(prjPaySchFeeId));
            qcList = this.prjPaySchSplmtService.searchList(qc);
        }
        ListPageVO<PrjPaySchSplmtVO> listPage = new ListPageVO<PrjPaySchSplmtVO>(qcList, null);
        return listPage;
    }

    /**
     * 到补充信息添加修改页面
     */
    @RequestMapping(value = "toselectByattachment.do", method = {RequestMethod.GET})
    public ModelAndView selectByattachment(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toRejectAddandAlterPage", "加载toRejectAddandAlterPage添加修改页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView view = new ModelAndView("project/prjprdquatprps/selectByattachmentPage");
        String pkId = request.getParameter("id");
        view.addObject("pkId", pkId);
        return view;
    }


    /**
     * 到补充信息添加修改页面
     */
    @RequestMapping(value = "toRejectAddandAlterPage.do", method = {RequestMethod.GET})
    public ModelAndView toRejectAddandAlterPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toRejectAddandAlterPage", "加载toRejectAddandAlterPage添加修改页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView view = new ModelAndView("project/prjprdquatprps/rejectAddandAlterPage");
        String id = request.getParameter("id");
        String prjPaySchFeeId = request.getParameter("prjPaySchFeeId");
        String SupplementDt = null;
        if (StringUtils.isNotBlank(id)) {
            PrjPaySchSplmtVO vo = this.prjPaySchSplmtService.selectById(Long.valueOf(id));
            SupplementDt = DateUtils.formatDateToString(vo.getSupplementDt(), DateUtils.YYYY_MM_DD);
            vo.setSupplementAmts(DecimalUtils.convertFenToYuan(vo.getSupplementAmt()));
            vo.setSupplementDtZH(SupplementDt);
            view.addObject("prjPaySchSplmtVO", vo);
        }
        view.addObject("prjPaySchFeeId", prjPaySchFeeId);
        return view;
    }

    /**
     * 补充信息添加操作
     */
    @RequestMapping(value = "/rejectAdd.do", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public Object rejectAdd(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
        PrjPaySchSplmtVO entity = null;//获取参数
        try {
            entity = this.getRequestParamForInsTypInfo(request);//获取参数
            Long id = this.prjPaySchSplmtService.add(entity);
            //附件信息维护
            List<SysUlFilesRecVO> sysUlFilesRecVOs = entity.getUploadFilesRecVOs();
            if (CollectionUtils.isNotEmpty(sysUlFilesRecVOs)) {
                for (SysUlFilesRecVO sysUlFilesRecVO : sysUlFilesRecVOs) {
                    sysUlFilesRecVO.setPkId(String.valueOf(id));
                    sysUlFilesRecVO.setTabNm("PRJ_PAY_SCH_SPLMT");
                    sysUlFilesRecVO.setIsDel(BaseConstant.IS_YESNO_NO);
                    sysUlFilesRecVO.setSysCd(CurrentThreadContext.getCurrentSysCd());
                    sysUlFilesRecVO.setCfgCd(PrjPrdLicInfoConstant.PRJ_PRD_LIC_FILE_CODE);
                    sysUlFilesRecVO.setCfgDtlCd(PrjPrdLicInfoConstant.PRJ_PRD_LIC_FILE_DETAIL_CODE);
                    this.sysUlFilesRecService.add(sysUlFilesRecVO);
                }
            }
            result.setData(id);
            result.setSuccess(BaseConstant.IS_YESNO_YES);
            result.setInfo(SysLogConstant.LOG_CMM_ADD_SUCC);
            BaseLogUtils.info(logger, "addInsTypInfo", "新增PrjPaySchSplmt数据成功,ID:" + id + ".DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.info(logger, "addInsTypInfo", "新增PrjPaySchSplmt数据失败.DATA:" + JSONObject.toJSONString(entity) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.error(logger, "addInsTypInfo", "新增PrjPaySchSplmt数据失败,系统错误.DATA:" + JSONObject.toJSONString(entity) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }

    /**
     * 补充信息修改操作
     */
    @RequestMapping(value = "/rejectModify.do", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public Object rejectModify(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
        PrjPaySchSplmtVO entity = null;
        try {
            entity = this.getRequestParamForInsTypInfo(request);
            if (entity.getId() == null) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
                BaseLogUtils.info(logger, "modifyInsTypInfo", "修改InsTypInfo信息,主键参数为空！.ID:" + entity.getId(), CurrentThreadContext.getCurrentUserName());
                result.setSuccess(BaseConstant.IS_YESNO_YES);
                result.setInfo(SysLogConstant.LOG_CMM_UPDATE_SUCC);
                return result;
            }

            boolean success = this.prjPaySchSplmtService.modify(entity);
            //附件信息维护
            List<SysUlFilesRecVO> sysUlFilesRecVOs = entity.getUploadFilesRecVOs();
            if (CollectionUtils.isNotEmpty(sysUlFilesRecVOs)) {
                for (SysUlFilesRecVO sysUlFilesRecVO : sysUlFilesRecVOs) {
                    sysUlFilesRecVO.setPkId(String.valueOf(entity.getId()));
                    sysUlFilesRecVO.setTabNm("PRJ_PAY_SCH_SPLMT");
                    sysUlFilesRecVO.setIsDel(BaseConstant.IS_YESNO_NO);
                    sysUlFilesRecVO.setSysCd(CurrentThreadContext.getCurrentSysCd());
                    sysUlFilesRecVO.setCfgCd(PrjPrdLicInfoConstant.PRJ_PRD_LIC_FILE_CODE);
                    sysUlFilesRecVO.setCfgDtlCd(PrjPrdLicInfoConstant.PRJ_PRD_LIC_FILE_DETAIL_CODE);
                    this.sysUlFilesRecService.add(sysUlFilesRecVO);
                }
            }
            if (!success) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_UPDATE_FAIL);
                BaseLogUtils.info(logger, "modifyInsTypInfo", "修改InsTypInfo数据失败.DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
                return result;
            }
            BaseLogUtils.info(logger, "modifyInsTypInfo", "修改InsTypInfo数据成功.DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.info(logger, "modifyInsTypInfo", "修改InsTypInfo数据失败.DATA:" + JSONObject.toJSONString(entity) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.error(logger, "modifyInsTypInfo", "修改InsTypInfo数据失败,系统错误.DATA:" + JSONObject.toJSONString(entity) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }

    /**
     * 补充信息删除操作
     */
    @RequestMapping(value = "/rejectRemoveById.do", method = {RequestMethod.POST})
    @ResponseBody
    public DataResultVO rejectRemoveById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String id = request.getParameter("id");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
        if (StringUtils.isEmpty(id)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.info(logger, "removeInsTypInfoByIds", "删除InsTypInfo数据,主键参数为空!", CurrentThreadContext.getCurrentUserName());
            return result;
        }
        try {
            boolean success = this.prjPaySchSplmtService.removeById(Long.valueOf(id));
            if (!success) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_DELETE_FAIL);
                BaseLogUtils.info(logger, "removeInsTypInfoByIds", "删除InsTypInfo数据失败,ID:" + id.toString(), CurrentThreadContext.getCurrentUserName());
            }
            BaseLogUtils.info(logger, "removeInsTypInfoByIds", "删除InsTypInfo数据成功,ID:" + id.toString(), CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.info(logger, "removeInsTypInfoByIds", "删除InsTypInfo数据失败,ID:" + id.toString() + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "removeInsTypInfoByIds", "删除InsTypInfo数据失败,系统错误.ID:" + id.toString() + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }

    /**
     * 获取补充信息表的请求参数
     *
     * @param request 请求
     * @return
     */
    private PrjPaySchSplmtVO getRequestParamForInsTypInfo(HttpServletRequest request) throws BaseException {
        //获取参数
        String id = request.getParameter("id");//主键
        String prjPaySchFeeId = request.getParameter("prjPaySchFeeId");//支付费用信息id
        String supplementAmt = request.getParameter("supplementAmt");//补充金额
        String supplementDt = request.getParameter("supplementDt");//补充时间
        String supplementRem = request.getParameter("supplementRem");//备注
        String fileParams = request.getParameter("fileParams");//文件资料

        PrjPaySchSplmtVO entity = new PrjPaySchSplmtVO();
        Date regDate = null;
        //验证参数
        if (StringUtils.isBlank(supplementAmt)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "补充金额不能为空.");
        }
        if (StringUtils.isBlank(supplementDt)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "补充时间不能为空.");
        } else {
            regDate = DateUtils.formatStringToDate(supplementDt, DateUtils.YYYY_MM_DD);
        }
        if (StringUtils.isNotBlank(fileParams)) {
            //解析附件上传信息
            JSONArray arry = JSONArray.fromObject(fileParams);
            List<SysUlFilesRecVO> uploadFilesRecVOs = new ArrayList<SysUlFilesRecVO>();
            if (arry.size() > 0) {
                for (int i = 0; i < arry.size(); i++) {
                    net.sf.json.JSONObject jsonObject = arry.getJSONObject(i);
                    SysUlFilesRecVO sysUlFilesRecVO = new SysUlFilesRecVO();
                    sysUlFilesRecVO.setFileNm(jsonObject.getString("fileNm"));
                    sysUlFilesRecVO.setFilePath(jsonObject.getString("filePath"));
                    sysUlFilesRecVO.setSysCd(CurrentThreadContext.getCurrentSysCd());
                    sysUlFilesRecVO.setOrgCd(PrjBscInfoConstant.CODE_PRJ_FILE_DEF_ORG);
                    sysUlFilesRecVO.setAbsLocPath(PropertiesCacheUtils.getProperty(UploadConstant.UPLOAD_ROOT_PATH) + sysUlFilesRecVO.getFilePath());
                    uploadFilesRecVOs.add(sysUlFilesRecVO);
                }
                entity.setUploadFilesRecVOs(uploadFilesRecVOs);
            }
        }

        String remove = ".";
        String removeSupplementAmt = "";
        boolean res = supplementAmt.contains(".");
        if (res == true) {
            removeSupplementAmt = supplementAmt.replace(remove, "");
            entity.setSupplementAmt(Long.valueOf(removeSupplementAmt));
        } else {
            entity.setSupplementAmt(Long.valueOf(supplementAmt));
        }

        entity.setSupplementDt(regDate);
        entity.setSupplementRem(supplementRem);
        if (StringUtils.isBlank(id)) {
            entity.setPrjPaySchFeeId(Long.valueOf(prjPaySchFeeId));
        }

        Date tm = new Date();
        if (StringUtils.isNotBlank(id)) {
            entity.setId(Long.valueOf(id));
            entity.setMdfTm(tm);
            entity.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
        } else {
            entity.setCrtTm(tm);
            entity.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
        }
        return entity;
    }

    /**
     * 到支付表管理列表页面
     */
    @RequestMapping(value = "/toPrjPrdPaySchMMgrPage.do", method = {RequestMethod.GET})
    public ModelAndView toPrjPrdPaySchMMgrPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toListPage", "加载PrjPrdPaySchM列表页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView view = new ModelAndView("project/prjprdquatprps/prjPrdPaySchMMgrPage");
        //项目类型
        List<KeyValueVO> projectTypeList = this.prjBscInfoService.getPrjTypCdALLKV();
        //业务类型
        List<KeyValueVO> bizTypeList = this.prjBscInfoService.getBizTypeList();
        // 事业部
        List<KeyValueVO> orgList = this.cstBscInfoService.searchBusinessOrgList();
        //业务类型
        List<KeyValueVO> prdStsCdList = this.prjBscInfoService.getPrdStsCdList();
        //标签类型
        List<KeyValueVO> tagTypeCdList = this.sysDictionaryApiService.getKvList("PRJ0250", CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
        // 一级支付表状态
        List<KeyValueVO> firstPrdStsCdList = this.sysDictionaryApiService.getKvList(PrjPrdPaySchMConstant.FIRST_PRD_STS_CD, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
        String quitPrioFlag = "0";//默认没有访问权限
        List<SysResourceDTO> quitPrioList = this.priorityApiService.searchFuncWithAuth(CurrentThreadContext.getCurrentSysCd(),
                CurrentThreadContext.getCurrentRoleId(),"140701");
        if(CollectionUtils.isNotEmpty(quitPrioList)){
            //表示该角色对140701（退换车标签有访问权限）
            quitPrioFlag = "1";
        }
        //是否
        List<KeyValueVO> yesOrNoCdList = sysDictionaryApiService.getKvList(DictionaryConstant.CODE_SYS_YES_NO_CD, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
        view.addObject("firstPrdStsCdList", firstPrdStsCdList);
        view.addObject("yesOrNoCdList", yesOrNoCdList);
        view.addObject("orgListList", orgList);
        view.addObject("projectTypeList", projectTypeList);
        view.addObject("bizTypeList", bizTypeList);
        view.addObject("prdStsCdList", prdStsCdList);
        view.addObject("tagTypeCdList", tagTypeCdList);
        view.addObject("currentBuOrgCd", CurrentThreadContext.getCurrentBuOrgCd());
        view.addObject("quitPrioFlag", quitPrioFlag);
        return view;
    }

    /**
     * 到资方支付表管理列表页面
     */
    @RequestMapping(value = "/toPrjPrdZfPaySchMMgrPage.do", method = {RequestMethod.GET})
    public ModelAndView toPrjPrdZfPaySchMMgrPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toListPage", "加载PrjPrdZfPaySchM列表页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView view = new ModelAndView("project/prjprdquatprps/prjPrdZfPaySchMMgrPage");
        //业务线字典List
        List<KeyValueVO> bussinessLineDicList = sysDictionaryApiService.getKvList("REF0048","11000","0000");
        //查询第三方机构
        List<FriBaseInfoVO> list = this.overdueService.getFriBaseInfoList();
        //根据金融机构业务线,设置金融机构名称展示字段值
        FundRasInsNmChangeUtil.insNmShowAddBussinessLineDic(list,bussinessLineDicList);
        view.addObject("friBaseList", list);
        return view;
    }

    /**
     * 到支付表管理列表页面(简化版)
     */
    @RequestMapping(value = "/toPrjPrdPaySchMMgrPageSimple.do", method = {RequestMethod.GET})
    public ModelAndView toPrjPrdPaySchMMgrPageSimple(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toListPage", "加载PrjPrdPaySchM列表页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView view = new ModelAndView("project/prjprdquatprps/prjPrdPaySchMMgrPageSimple");
        //项目类型
        List<KeyValueVO> projectTypeList = this.prjBscInfoService.getPrjTypCdALLKV();
        //业务类型
        List<KeyValueVO> bizTypeList = this.prjBscInfoService.getBizTypeList();
        // 事业部
        List<KeyValueVO> orgList = this.cstBscInfoService.searchBusinessOrgList();
        //业务类型
        List<KeyValueVO> prdStsCdList = this.prjBscInfoService.getPrdStsCdList();
        view.addObject("orgListList", orgList);
        view.addObject("projectTypeList", projectTypeList);
        view.addObject("bizTypeList", bizTypeList);
        view.addObject("prdStsCdList", prdStsCdList);
        view.addObject("currentBuOrgCd", CurrentThreadContext.getCurrentBuOrgCd());
        return view;
    }

    /**
     * 到修改支付表起租日列表页面
     */
    @RequestMapping(value = "/toPrjPrdPaySchMMgrPageForUpdate.do", method = {RequestMethod.GET})
    public ModelAndView toPrjPrdPaySchMMgrPageForUpdate(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toListPage", "加载PrjPrdPaySchM列表页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView view = new ModelAndView("project/prjprdquatprps/prjPrdPaySchMMgrPage");
        //项目类型
        List<KeyValueVO> projectTypeList = this.prjBscInfoService.getPrjTypCdALLKV();
        //业务类型
        List<KeyValueVO> bizTypeList = this.prjBscInfoService.getBizTypeList();
        // 事业部
        List<KeyValueVO> orgList = this.cstBscInfoService.searchBusinessOrgList();
        //业务类型
        List<KeyValueVO> prdStsCdList = this.prjBscInfoService.getPrdStsCdList();
        view.addObject("orgListList", orgList);
        view.addObject("projectTypeList", projectTypeList);
        view.addObject("bizTypeList", bizTypeList);
        view.addObject("prdStsCdList", prdStsCdList);
        view.addObject("update", "0");
        view.addObject("currentBuOrgCd", CurrentThreadContext.getCurrentBuOrgCd());
        return view;
    }

    /**
     * 到提前结清选择结清期数页面
     */
    @RequestMapping(value = "/showChoosePreSettlePdPage.do", method = {RequestMethod.GET})
    public ModelAndView showChoosePreSettlePdPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("到提前结清选择结清期数页面." + CurrentThreadContext.getCurrentUserName()).info();
        String paySchId = request.getParameter("paySchId");//支付表ID
        String prjId = request.getParameter("prjId");
        String payPd = request.getParameter("payPd");//期数
        // String startLsPd = request.getParameter("startLsPd");//开始期数
        String paySchNo = request.getParameter("paySchNo");//支付表号
        PrjBscInfoVO prj = null;
        Integer startLsPd = null;
        Integer defStartLsPd = null;
        Integer zckcFlag = BaseConstant.IS_YESNO_NO;
        if (StringUtils.isNotBlank(prjId)) {
            prj = this.prjBscInfoService.selectById(Long.valueOf(prjId));
            if (prj.getCstMgrOrgCd().contains(PrjBscInfoConstant.CODE_ORG_CD_KCRZ)) {
                zckcFlag = BaseConstant.IS_YESNO_YES;
            }
        }
        PrjPrdPaySchMVO paySchMVO = this.prjPrdPaySchMService.getPrjPrdPaySettPayPd(Long.valueOf(paySchId), PrjPrdPaySchMConstant.PRJ_PRD_Pay_SCH_M_PRE, new Date());
        if (null != paySchMVO) {
            startLsPd = paySchMVO.getStartLsPd();
            defStartLsPd = paySchMVO.getDefStartLsPd();
        }
        ModelAndView view = new ModelAndView("project/prjprdquatprps/prjPayPreSettleChoosePd");
        view.addObject("payPd", payPd);
        view.addObject("startLsPd", startLsPd);
        view.addObject("defStartLsPd", defStartLsPd);
        view.addObject("prj", prj);
        view.addObject("paySchId", paySchId);
        view.addObject("paySchNo", paySchNo);
        view.addObject("zckcFlag", zckcFlag);
        return view;
    }


    /**
     * 到正常结清选择结清期数页面
     */
    @RequestMapping(value = "/showChooseSettlePdPage.do", method = {RequestMethod.GET})
    public ModelAndView showChooseSettlePdPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("到正常结清选择结清期数页面."+CurrentThreadContext.getCurrentUserName()).info();
        String paySchId = request.getParameter("paySchId");//支付表ID
        String prjId = request.getParameter("prjId");
        String payPd = request.getParameter("payPd");//期数
        // String startLsPd = request.getParameter("startLsPd");//开始期数
        String paySchNo = request.getParameter("paySchNo");//支付表号
        PrjBscInfoVO prj = null;
        Integer startLsPd = null;
        Integer defStartLsPd = null;
        if (StringUtils.isNotBlank(prjId)) {
            prj = this.prjBscInfoService.selectById(Long.valueOf(prjId));
        }
        PrjPrdPaySchMVO paySchMVO = this.prjPrdPaySchMService.getPrjPrdPaySettPayPd(Long.valueOf(paySchId), PrjPrdPaySchMConstant.PRJ_PRD_Pay_SCH_M_PRE, new Date());
        if (null != paySchMVO) {
            startLsPd = paySchMVO.getStartLsPd();
            defStartLsPd = paySchMVO.getDefStartLsPd();
        }
        ModelAndView view = new ModelAndView("project/prjprdquatprps/prjPaySettleChoosePd");
        view.addObject("payPd", payPd);
        view.addObject("startLsPd", startLsPd);
        view.addObject("prj", prj);
        view.addObject("paySchId", paySchId);
        view.addObject("paySchNo", paySchNo);
        view.addObject("defStartLsPd", defStartLsPd);
        return view;
    }


    /**
     * 显示提前结清详情页面
     */
    @RequestMapping(value = "/showPreSettlePage.do", method = {RequestMethod.GET})
    public ModelAndView showPreSettlePage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("显示提前结清详情页面."+CurrentThreadContext.getCurrentUserName()).info();
        String paySchId = request.getParameter("paySchId");//支付表ID
        String payPdStr = request.getParameter("payPd");//提前结清时结清期数
        PrjBscInfoVO prj = null;
        PrjPrdPaySchMVO pay = null;
        //CstBscInfoVO cst = null;
        ListPageVO<PrjPrdPrpsFeeDetailVO> listPage = null;
        ListPageVO<PrjPrdPaySchDVO> feeListPage = null;
        PrjPrdDtlVO dtl = null;
        //Integer actPayPd = null;//实际还到的期数
        Integer payPd = null;//期数
        double settPctValue = 0d;//结清比例
        double extContAmt = 0d;//合同外优惠金额
        double reduAmt = 0d;//优惠金额
        Integer yzdgFlag = BaseConstant.IS_YESNO_NO;
        Integer zckcFlag = BaseConstant.IS_YESNO_NO;// 专车客车标识
        double after12LastRntAmt = 0d;
        if (StringUtils.isNotBlank(payPdStr)) {
            payPd = Integer.valueOf(payPdStr);
        }
        int reduStartPd = payPd;
        try {
            if (StringUtils.isEmpty(paySchId)) {
                throw new BaseException("支付表ID不能为空！");
            }
            pay = this.prjPrdPaySchMService.searchPreSettleData(Long.valueOf(paySchId), new Date(), payPd);
            // 已经有返回，如果为空，则进行数据库查询
            dtl = pay.getDtlVO();
            if (dtl == null) {
                PrjPrdDtlQueryCondition qc = new PrjPrdDtlQueryCondition();
                qc.setPaySchId(pay.getWsPaySchId());
                List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(qc);
                if (CollectionUtils.isNotEmpty(dtlList)) {
                    dtl = dtlList.get(0);
                }
            }

            // 页面只取了cstNm，对象prj中有，此处无需再次查询数据库
            //cst = this.cstBscInfoService.selectDetailById(pay.getCstId());
            prj = this.prjBscInfoService.selectById(pay.getPrjId());
            if (prj.getCstMgrOrgCd().contains(PrjBscInfoConstant.CODE_ORG_CD_YZDG)) {
                yzdgFlag = BaseConstant.IS_YESNO_YES;
            }
            if (prj.getCstMgrOrgCd().contains(PrjBscInfoConstant.CODE_ORG_CD_KCRZ)) {
                zckcFlag = BaseConstant.IS_YESNO_YES;
            }

            if (CollectionUtils.isNotEmpty(pay.getPrjPrdPayDetailList())) {
                List<PrjPrdPrpsFeeDetailVO> feeList = pay.getPrjPrdPayDetailList();
                listPage = new ListPageVO<>(feeList, feeList.size());
                //pay.setPrjQuatPrpsPaySchPage(listPage);
            }
            if (CollectionUtils.isNotEmpty(pay.getFeeDetailList())) {
                List<PrjPrdPaySchDVO> list = new ArrayList<PrjPrdPaySchDVO>();
                for (PrjPrdPaySchDVO prjPrdPaySchDVO : pay.getFeeDetailList()) {
                    if (prjPrdPaySchDVO.getFeeClsCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_PRPS)) {
                        list.add(prjPrdPaySchDVO);
                    }
                    if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_300)) {
                        settPctValue = prjPrdPaySchDVO.getFeePct();
                    }
                    if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_301)) {
                        extContAmt = prjPrdPaySchDVO.getFeeAmt();
                    }
                    if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_201) && null != prjPrdPaySchDVO.getIsSysDef() && prjPrdPaySchDVO.getIsSysDef().intValue() == 1) {
                        reduAmt = prjPrdPaySchDVO.getFeeAmt();
                    }
                    if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_302)) {
                        reduStartPd = prjPrdPaySchDVO.getFeePct().intValue();
                    }
                }
                if (settPctValue == 0) {
                    yzdgFlag = BaseConstant.IS_YESNO_NO;
                }
                //首期款合计项
                PrjPrdPaySchDVO tatal = new PrjPrdPaySchDVO();
                tatal.setFeeTypCdNm("首期款合计");
                tatal.setFeeAmt(pay.getFirstPayAmt());
                tatal.setPaidUpAmt(pay.getTotalFirstPayAmt().longValue());
                list.add(tatal);
                feeListPage = new ListPageVO<PrjPrdPaySchDVO>(list, list.size());
                pay.setFeeDetailListPage(feeListPage);
            }
            //double afterPayPdAmt = 0d;//自结清之后的金额
            for (PrjPrdPrpsFeeDetailVO detail : pay.getPrjPrdPayDetailList()) {
                //以租代购12期之后的租金
                if (detail.getPayPd().intValue() > reduStartPd) {
                    after12LastRntAmt = DecimalUtils.add(after12LastRntAmt, detail.getRntAmt());
                }
            }
            if (CollectionUtils.isNotEmpty(pay.getSubFeeAmtTotalList())) {
                for (PrjPrdPaySchDVO paySchDVO : pay.getSubFeeAmtTotalList()) {
                    paySchDVO.setFeeAmt(DecimalUtils.convertFenToYuan(paySchDVO.getFeeAmt().longValue()));
                }
            }
            List<SysDictionaryVO> settFeeTypCdListJSON = this.prjPrdPaySchMService.getSettFeeTypList();
            ModelAndView view = new ModelAndView("project/prjprdquatprps/prjPrdPaySchMPerSettleDetailPage");
            view.addObject("pay", pay);
            //view.addObject("cst", cst);
            view.addObject("prj", prj);
            view.addObject("dtl", dtl);
            view.addObject("settFeeTypCdListJSON", JSON.toJSONString(settFeeTypCdListJSON));
            if (CollectionUtils.isNotEmpty(pay.getSubFeeAmtTotalList())) {
                view.addObject("subFeeAmtTotalList", JSON.toJSONString(pay.getSubFeeAmtTotalList()));
            }
            view.addObject("listPage", JSON.toJSONString(listPage));
            view.addObject("feeListPage", JSON.toJSONString(feeListPage));
            view.addObject("paySchId", pay.getId());// 返回已启用的支付表ID给页面
            view.addObject("settPctValue", settPctValue);
            view.addObject("extContAmt", extContAmt);
            view.addObject("reduAmt", reduAmt);
            view.addObject("yzdgFlag", yzdgFlag);
            view.addObject("zckcFlag", zckcFlag);
            view.addObject("after12LastRntAmt", after12LastRntAmt);
            view.addObject("model", "preview");// 代表结清申请预览
            // 发起结清按钮权限
            view.addObject("showStlBtn", prjPrdPaySchMService.settleAuthority(pay.getId()));
            return view;
        } catch (BaseException ex) {
            BaseLogUtils.newLogger("显示提前结清详情页面查询失败！").setBussinessId(paySchId).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
            throw ex;
        } catch (Exception ex) {
            BaseLogUtils.newLogger("显示提前结清详情页面查询失败！").setBussinessId(paySchId).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
            throw ex;
        }
    }


    /**
     * 显示提前结清添加费用项页面
     */
    @RequestMapping(value = "/addPreSettleFeePage.do", method = {RequestMethod.GET})
    public ModelAndView addPreSettleFeePage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("显示提前结清详情页面."+CurrentThreadContext.getCurrentUserName()).info();
        String paySchId = request.getParameter("paySchId");//支付表ID
        //String addSetDateFlag = request.getParameter("addSetDateFlag");//当结清时间为
        String isDetail = request.getParameter("isDetail");
        String procInstId = request.getParameter("processInstanceId");//流程实例ID_FUJINGRUN
        String taskDefKey = request.getParameter("taskDefKey");// 例如：FLOW_00000001_063_001_001
        Integer payPd = null;//提前结清时结清期数
        PrjBscInfoVO prj = null;
        PrjPrdPaySchMVO pay = null;
        //CstBscInfoVO cst = null;
        ListPageVO<PrjPrdPrpsFeeDetailVO> listPage = null;
        ListPageVO<PrjPrdPaySchDVO> feeListPage = null;
        PrjPrdDtlVO dtl = null;
        Date applyDate = null;
        double after12LastRntAmt = 0d;//以租代购12期之后剩余租金
        double settPctValue = 0d;//结清比例
        double extContAmt = 0d;//合同外优惠金额
        double reduAmt = 0d;//优惠金额
        List<KeyValueVO> settPctList = null;
        Integer yzdgFlag = BaseConstant.IS_YESNO_NO;
        int reduStartPd = 0;
        int lsPd = 1;
        ModelAndView view = new ModelAndView("project/prjprdquatprps/prjPrdPaySchMPerSettleAddFeePage");
        view.addObject("taskDefKey", taskDefKey);
        view.addObject("procInstId", procInstId);
        try {
            if (StringUtils.isNotBlank(paySchId)) {
                PrjStlMVO stlMVO = this.prjStlMService.selectByPaySchMId(Long.valueOf(paySchId), PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_CST);

                // 查找结清期数
                PrjPrdPaySchMVO schMVO = getSchMVO("", Long.valueOf(paySchId));
                payPd = schMVO.getStlPd();
                lsPd = schMVO.getLsPd();

                reduStartPd = payPd;

                pay = this.prjPrdPaySchMService.searchPreSettleData(Long.valueOf(paySchId), null, Integer.valueOf(payPd));
                // 已经有返回，如果为空，则进行数据库查询
                dtl = pay.getDtlVO();
                if (dtl == null) {
                    PrjPrdDtlQueryCondition qc = new PrjPrdDtlQueryCondition();
                    qc.setPaySchId(pay.getWsPaySchId());
                    List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(qc);
                    if (CollectionUtils.isNotEmpty(dtlList)) {
                        dtl = dtlList.get(0);
                    }
                }
                if (null != pay) {
                    //cst = this.cstBscInfoService.selectDetailById(pay.getCstId());
                    prj = this.prjBscInfoService.selectById(pay.getPrjId());
                    if (prj.getCstMgrOrgCd().contains(PrjBscInfoConstant.CODE_ORG_CD_YZDG)) {
                        yzdgFlag = BaseConstant.IS_YESNO_YES;
                    }
                    // 申请时间
                    applyDate = pay.getApplyDt();
                    if (null != stlMVO && null != applyDate && null != stlMVO.getStlStDt()
                            && org.apache.commons.lang3.time.DateUtils.isSameDay(applyDate, stlMVO.getStlStDt())) {
                        if (null != stlMVO.getRmS03ArTotAmt()) {
                            pay.setLastPrintAmt(stlMVO.getRmS03ArTotAmt() - (null == stlMVO.getStlOverdueS03Amt() ? 0 : stlMVO.getStlOverdueS03Amt()));
                        }
                        if (null != stlMVO.getRmS02ArTotAmt()) {
                            pay.setLastIntAmt(stlMVO.getRmS02ArTotAmt() - (null == stlMVO.getStlOverdueS02Amt() ? 0 : stlMVO.getStlOverdueS02Amt()));
                        }

                        if (null != stlMVO.getStlPenaltyAmt()) {
                            pay.setPenaltyAmt(stlMVO.getStlPenaltyAmt());
                        }
                        if (null != stlMVO.getStlOverdueAmt()) {
                            pay.setOverdueAmt(stlMVO.getStlOverdueAmt());
                        }
                        if (null != stlMVO.getStlAmt()) {
                            pay.setStlAmt(stlMVO.getStlAmt().longValue());
                            pay.setFinalPayAmt(stlMVO.getStlAmt());
                            pay.setTotalSettAmt(stlMVO.getStlAmt());
                        }
                    }
                }
            }
            if (CollectionUtils.isNotEmpty(pay.getPrjPrdPayDetailList())) {
                List<PrjPrdPrpsFeeDetailVO> feeList = null;
                double totalRnt = 0d;//租金
                double totalPrint = 0d;//本金
                double totalInt = 0d;//利息
                if (payPd != 0) {
                    //查询流程中临时状态的期数
                    Integer payPdFlow = null;
                    List<PrjPrdPaySchDVO> list = this.prjPrdPaySchDService.selectPaySchByDelStatusAndPaySchId(Long.valueOf(paySchId), PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                    BaseLogUtils.info(logger, "searchPreSettleData", "流程中临时状态的期数：" + JSON.toJSONString(list));

                    if (CollectionUtils.isNotEmpty(list)) {
                        payPdFlow = list.get(0).getPayPd();
                        BaseLogUtils.info(logger, "searchPreSettleData", "流程中临时状态的期数：" + JSON.toJSONString(payPdFlow));

                        feeList = new ArrayList<PrjPrdPrpsFeeDetailVO>();
                        for (PrjPrdPrpsFeeDetailVO payDetail : pay.getPrjPrdPayDetailList()) {
                            if (payDetail.getPayPd().intValue() < Integer.valueOf(payPdFlow).intValue()) {
                                totalRnt = DecimalUtils.add(totalRnt, payDetail.getRntAmt());
                                totalPrint = DecimalUtils.add(totalPrint, payDetail.getPrinAmt());
                                totalInt = DecimalUtils.add(totalInt, payDetail.getIntAmt());
                                feeList.add(payDetail);
                            }
                            if (payDetail.getPayPd().intValue() == Integer.valueOf(payPdFlow).intValue()) {
                                payDetail.setRntAmt(DecimalUtils.sub(pay.getTotalRntAmt(), totalRnt));
                                payDetail.setPrinAmt(DecimalUtils.sub(pay.getTotalPrinAmt(), totalPrint));
                                payDetail.setIntAmt(DecimalUtils.sub(pay.getTotalIntAmt(), totalInt));
                                payDetail.setRemPrinAmt(0d);
                                payDetail.setIsDel(PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                                feeList.add(payDetail);
                            }
                        }
                    } else {
                        feeList = pay.getPrjPrdPayDetailList();
                        //payPdFlow = payPd;
                    }
                } else {
                    feeList = pay.getPrjPrdPayDetailList();
                }
                listPage = new ListPageVO<PrjPrdPrpsFeeDetailVO>(feeList, feeList.size());
                pay.setPrjQuatPrpsPaySchPage(listPage);
            }
            if (CollectionUtils.isNotEmpty(pay.getFeeDetailList())) {
                List<PrjPrdPaySchDVO> list = new ArrayList<PrjPrdPaySchDVO>();
                for (PrjPrdPaySchDVO prjPrdPaySchDVO : pay.getFeeDetailList()) {
                    if (prjPrdPaySchDVO.getFeeClsCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_PRPS)) {
                        list.add(prjPrdPaySchDVO);
                    }
                    if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_300)) {
                        settPctValue = prjPrdPaySchDVO.getFeePct();
                    }
                    if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_301)) {
                        extContAmt = prjPrdPaySchDVO.getFeeAmt();
                    }
                    if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_301)) {
                        extContAmt = prjPrdPaySchDVO.getFeeAmt();
                    }
                    if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_302)) {
                        reduStartPd = prjPrdPaySchDVO.getFeePct().intValue();
                    }
                    if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_201) && null != prjPrdPaySchDVO.getIsSysDef() && prjPrdPaySchDVO.getIsSysDef().intValue() == 1) {
                        reduAmt = prjPrdPaySchDVO.getFeeAmt();
                    }
                }
                //首期款合计项
                PrjPrdPaySchDVO tatal = new PrjPrdPaySchDVO();
                tatal.setFeeTypCdNm("首期款合计");
                tatal.setFeeAmt(pay.getFirstPayAmt());
                tatal.setPaidUpAmt(pay.getTotalFirstPayAmt().longValue());
                list.add(tatal);
                feeListPage = new ListPageVO<PrjPrdPaySchDVO>(list, list.size());
                // feeListPage = new ListPageVO<PrjPrdPaySchDVO>(pay.getFeeDetailList(), pay.getFeeDetailList().size());
                pay.setFeeDetailListPage(feeListPage);
            }
            //double afterPayPdAmt = 0d;//自结清之后的金额
            for (PrjPrdPrpsFeeDetailVO detail : pay.getPrjPrdPayDetailList()) {
                //以租代购页面选择期数之后的租金
                if (detail.getPayPd().intValue() > reduStartPd) {
                    after12LastRntAmt = DecimalUtils.add(after12LastRntAmt, detail.getRntAmt());
                }
            }
            if (CollectionUtils.isNotEmpty(pay.getSubFeeAmtTotalList())) {
                for (PrjPrdPaySchDVO paySchDVO : pay.getSubFeeAmtTotalList()) {
                    paySchDVO.setFeeAmt(DecimalUtils.convertFenToYuan(paySchDVO.getFeeAmt().longValue()));
                }
            }
            settPctList = this.prjPrdPaySchMService.selectSettPctList();
            BaseLogUtils.info(logger, "searchPreSettleData", "settPctList：" + JSON.toJSONString(settPctList));

            //费用类型
            List<SysDictionaryVO> settFeeTypCdListJSON = this.prjPrdPaySchMService.getSettFeeTypList();

            view.addObject("pay", pay);
            //view.addObject("cst", cst);
            view.addObject("prj", prj);
            view.addObject("settPctValue", settPctValue);
            view.addObject("extContAmt", extContAmt);
            view.addObject("reduAmt", reduAmt);
            view.addObject("after12LastRntAmt", after12LastRntAmt);
            view.addObject("reduStartPd", reduStartPd);
            view.addObject("dtl", dtl);
            view.addObject("subFeeAmtTotalList", JSON.toJSONString(pay.getSubFeeAmtTotalList()));
            view.addObject("listPage", JSON.toJSONString(listPage));
            view.addObject("feeListPage", JSON.toJSONString(feeListPage));
            view.addObject("paySchId", paySchId);
            view.addObject("settFeeTypCdListJSON", JSON.toJSONString(settFeeTypCdListJSON));
            view.addObject("isDetail", isDetail);
            view.addObject("yzdgFlag", yzdgFlag);
            view.addObject("settPctList", settPctList);
            view.addObject("lsPd", lsPd);
            //view.addObject("settFeeList", JSON.toJSONString(settListPage));

            String isDetail_bk = request.getParameter("isDetail_bk");//标识是否详情_YAOXIURONG
            String showBk_oCIn = request.getParameter("showBk_oCIn");//加载我司收款账号维护页面
            String showBk_oCOut = request.getParameter("showBk_oCOut");//加载我司付款账号维护页面
            String editInto = request.getParameter("editInto");//我司付款_维护收款账号
            String editOut = request.getParameter("editOut");//我司付款_维护付款账号
            //如果为空 设置为1 使流程中每个节点都可以查看账户信息
            if (StringUtils.isEmpty(showBk_oCIn) && StringUtils.isEmpty(showBk_oCOut)) {
                showBk_oCIn = "1";
                showBk_oCOut = "1";
                isDetail_bk = "1";
            }
            view.addObject("showBk_oCIn", showBk_oCIn);
            view.addObject("isDetail_bk", isDetail_bk);
            view.addObject("showBk_oCOut", showBk_oCOut);
            view.addObject("editInto", editInto);
            view.addObject("editOut", editOut);
            //重卡提前结清-查询绑定资金数据
            BaseLogUtils.info(logger, "addPreSettleFeePage", "addPreSettleFeePage重卡提前结清-查询绑定资金数据开始，数据：" + JSON.toJSONString(view));
            view = findBindFundData(request, view, Long.parseLong(paySchId), pay.getWsPaySchId());
            BaseLogUtils.info(logger, "addPreSettleFeePage", "addPreSettleFeePage重卡提前结清-查询绑定资金数据结束，数据：" + JSON.toJSONString(view));
            view.addObject("wsPaySchId", pay.getWsPaySchId());
            view.addObject("fileAuth", request.getParameter("fileAuth"));
        } catch (BaseException ex) {
            BaseLogUtils.newLogger("结清添加费用项页面查询失败.").setBussinessId(paySchId).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
            throw ex;
        } catch (Exception ex) {
            BaseLogUtils.newLogger("结清添加费用项页面查询失败.").setBussinessId(paySchId).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
            throw ex;
        }
        return view;
    }

    /**
     * 显示提前结清添加费用项页面
     */
    @RequestMapping(value = "/preSettleFlowPage.do", method = {RequestMethod.GET})
    public ModelAndView preSettleFlowPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "preSettleFlowPage", "显示提前结清流程中详情页面.", CurrentThreadContext.getCurrentUserName());
        String paySchId = request.getParameter("paySchId");//支付表ID
        String isDetail_bk = request.getParameter("isDetail_bk");//标识是否详情_YAOXIURONG
        String showBk_oCIn = request.getParameter("showBk_oCIn");//加载我司收款账号维护页面
        String showBk_oCOut = request.getParameter("showBk_oCOut");//加载我司付款账号维护页面
        String editInto = request.getParameter("editInto");//我司付款_维护收款账号
        String editOut = request.getParameter("editOut");//我司付款_维护付款账号
        String confirm = request.getParameter("confirm");
        //如果为空 设置为1 使流程中每个节点都可以查看账户信息
        List<KeyValueVO> settPctList = null;
        if (StringUtils.isEmpty(showBk_oCIn) && StringUtils.isEmpty(showBk_oCOut)) {
            showBk_oCIn = "1";
            showBk_oCOut = "1";
            isDetail_bk = "1";
        }

        String openTheBillAdd = request.getParameter("optba");//标识是否需要开票新增列表页面_FUJINGRUN
        String openTheBillForFinance = request.getParameter("optbf");//标识是否显示财务开票列表页面_FUJINGRUN
        String openTheBillForDetail = request.getParameter("optbd");//是否显示开票详细列表页面_FUJINGRUN
        String procInstId = request.getParameter("processInstanceId");//流程实例ID_FUJINGRUN
        Integer payPd = 0;//提前结清时结清期数
        PrjBscInfoVO prj = null;
        PrjPrdPaySchMVO pay = null;
        CstBscInfoVO cst = null;
        ListPageVO<PrjPrdPrpsFeeDetailVO> listPage = null;
        ListPageVO<PrjPrdPaySchDVO> feeListPage = null;
        PrjPrdDtlVO dtl = null;
        Date applyDate = null;
        double discountAmt = 0d;
        double breachAmt = 0d;
        double after12LastRntAmt = 0d;
        Integer yzdgFlag = BaseConstant.IS_YESNO_NO;
        double settPctValue = 0d;//结清比例
        double extContAmt = 0d;//合同外优惠金额
        double reduAmt = 0d;//优惠金额
        int reduStartPd = 0;
        ModelAndView view = new ModelAndView("project/prjprdquatprps/prjPrdPaySchMPerSettleFlowPage");
        try {
            if (StringUtils.isNotBlank(paySchId)) {
                // 查找结清期数
                PrjPrdPaySchMVO schMVO = getSchMVO(procInstId, Long.valueOf(paySchId));
                payPd = schMVO.getStlPd();

                reduStartPd = payPd;
                PrjStlMVO stlMVO = this.prjStlMService.selectByPaySchMId(Long.valueOf(paySchId), PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_CST);
                pay = this.prjPrdPaySchMService.searchPreSettleData(Long.valueOf(paySchId), null, Integer.valueOf(payPd));

                List<PrjPrdPaySchDVO> payFeeList = pay.getFeeDetailList();
                if (CollectionUtils.isNotEmpty(payFeeList)) {
                    for (PrjPrdPaySchDVO prjPrdPaySchDDTO : payFeeList) {
                        if (prjPrdPaySchDDTO.getFeeClsCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_SETT) && null != prjPrdPaySchDDTO.getIsSysDef() && prjPrdPaySchDDTO.getIsSysDef().equals(BaseConstant.IS_YESNO_YES)) {
                            if (prjPrdPaySchDDTO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_201)) {
                                discountAmt = prjPrdPaySchDDTO.getFeeAmt();
                            }
                            if (prjPrdPaySchDDTO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_103)) {
                                breachAmt = prjPrdPaySchDDTO.getFeeAmt();
                            }
                        }
                    }
                }
                // 申请时间
                applyDate = pay.getApplyDt();
                if (null != stlMVO && null != applyDate && null != stlMVO.getStlStDt()
                        && org.apache.commons.lang3.time.DateUtils.isSameDay(applyDate, stlMVO.getStlStDt())) {
                    if (null != stlMVO.getRmS03ArTotAmt()) {
                        pay.setLastPrintAmt(stlMVO.getRmS03ArTotAmt() - (null == stlMVO.getStlOverdueS03Amt() ? 0 : stlMVO.getStlOverdueS03Amt()));
                    }
                    if (null != stlMVO.getRmS02ArTotAmt()) {
                        pay.setLastIntAmt(stlMVO.getRmS02ArTotAmt() - (null == stlMVO.getStlOverdueS02Amt() ? 0 : stlMVO.getStlOverdueS02Amt()));
                    }

                    if (null != stlMVO.getStlPenaltyAmt()) {
                        pay.setPenaltyAmt(stlMVO.getStlPenaltyAmt());
                    }
                    if (null != stlMVO.getStlOverdueAmt()) {
                        pay.setOverdueAmt(stlMVO.getStlOverdueAmt());
                    }
                    if (null != stlMVO.getStlAmt()) {
                        pay.setStlAmt(stlMVO.getStlAmt().longValue());
                        pay.setFinalPayAmt(stlMVO.getStlAmt());
                        pay.setTotalSettAmt(stlMVO.getStlAmt());
                    }
                }
                pay.setBreachAmt(breachAmt);
                pay.setDiscountAmt(discountAmt);
                PrjPrdDtlQueryCondition qc = new PrjPrdDtlQueryCondition();
                qc.setPaySchId(pay.getWsPaySchId());
                List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(qc);
                if (CollectionUtils.isNotEmpty(dtlList)) {
                    dtl = dtlList.get(0);
                }
                if (null != pay) {
                    cst = this.cstBscInfoService.selectDetailById(pay.getCstId());
                    prj = this.prjBscInfoService.selectById(pay.getPrjId());
                    if (prj.getCstMgrOrgCd().contains(PrjBscInfoConstant.CODE_ORG_CD_YZDG)) {
                        yzdgFlag = BaseConstant.IS_YESNO_YES;
                    }
                }

                if (CollectionUtils.isNotEmpty(pay.getPrjPrdPayDetailList())) {
                    List<PrjPrdPrpsFeeDetailVO> feeList = null;
                    double totalRnt = 0d;//租金
                    double totalPrint = 0d;//本金
                    double totalInt = 0d;//利息

                    if (payPd != 0) {
                        //查询流程中临时状态的期数
                        Integer payPdFlow = null;
                        List<PrjPrdPaySchDVO> list = this.prjPrdPaySchDService.selectPaySchByDelStatusAndPaySchId(Long.valueOf(paySchId), PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                        if (CollectionUtils.isNotEmpty(list)) {
                            payPdFlow = list.get(0).getPayPd();
                            feeList = new ArrayList<PrjPrdPrpsFeeDetailVO>();
                            for (PrjPrdPrpsFeeDetailVO payDetail : pay.getPrjPrdPayDetailList()) {
                                if (payDetail.getPayPd().intValue() < Integer.valueOf(payPdFlow).intValue()) {
                                    totalRnt = DecimalUtils.add(totalRnt, payDetail.getRntAmt());
                                    totalPrint = DecimalUtils.add(totalPrint, payDetail.getPrinAmt());
                                    totalInt = DecimalUtils.add(totalInt, payDetail.getIntAmt());
                                    feeList.add(payDetail);
                                }
                                if (null != stlMVO) {
                                    if (payDetail.getPayPd().intValue() == Integer.valueOf(payPdFlow).intValue()) {
                                        payDetail.setRntAmt(stlMVO.getRmS01ArTotAmt());
                                        payDetail.setPrinAmt(stlMVO.getRmS03ArTotAmt());
                                        payDetail.setIntAmt(stlMVO.getRmS02ArTotAmt());
                                        payDetail.setRemPrinAmt(0d);
                                        payDetail.setIsDel(PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                                        feeList.add(payDetail);
                                    }
                                } else {
                                    if (payDetail.getPayPd().intValue() == Integer.valueOf(payPdFlow).intValue()) {
                                        payDetail.setRntAmt(DecimalUtils.sub(pay.getTotalRntAmt(), totalRnt));
                                        payDetail.setPrinAmt(DecimalUtils.sub(pay.getTotalPrinAmt(), totalPrint));
                                        payDetail.setIntAmt(DecimalUtils.sub(pay.getTotalIntAmt(), totalInt));
                                        payDetail.setRemPrinAmt(0d);
                                        payDetail.setIsDel(PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                                        feeList.add(payDetail);
                                    }
                                }
                            }
                        } else {
                            //payPdFlow = payPd;
                            feeList = pay.getPrjPrdPayDetailList();
                        }
                    } else {
                        feeList = pay.getPrjPrdPayDetailList();
                    }
                    listPage = new ListPageVO<PrjPrdPrpsFeeDetailVO>(feeList, feeList.size());
                    pay.setPrjQuatPrpsPaySchPage(listPage);
                }

                if (CollectionUtils.isNotEmpty(pay.getFeeDetailList())) {
                    List<PrjPrdPaySchDVO> list = new ArrayList<PrjPrdPaySchDVO>();
                    for (PrjPrdPaySchDVO prjPrdPaySchDVO : pay.getFeeDetailList()) {
                        if (prjPrdPaySchDVO.getFeeClsCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_PRPS)) {
                            list.add(prjPrdPaySchDVO);
                        }
                        if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_300)) {
                            settPctValue = prjPrdPaySchDVO.getFeePct();
                        }
                        if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_301)) {
                            extContAmt = prjPrdPaySchDVO.getFeeAmt();
                        }
                        if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_302)) {
                            reduStartPd = prjPrdPaySchDVO.getFeePct().intValue();
                        }
                        if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_201) && null != prjPrdPaySchDVO.getIsSysDef() && prjPrdPaySchDVO.getIsSysDef().intValue() == 1) {
                            reduAmt = prjPrdPaySchDVO.getFeeAmt();
                        }
                    }
                    //首期款合计项
                    PrjPrdPaySchDVO tatal = new PrjPrdPaySchDVO();
                    tatal.setFeeTypCdNm("首期款合计");
                    tatal.setFeeAmt(pay.getFirstPayAmt());
                    tatal.setPaidUpAmt(pay.getTotalFirstPayAmt().longValue());
                    list.add(tatal);
                    feeListPage = new ListPageVO<PrjPrdPaySchDVO>(list, list.size());
                    pay.setFeeDetailListPage(feeListPage);
                }
                //double afterPayPdAmt = 0d;//自结清之后的金额
                for (PrjPrdPrpsFeeDetailVO detail : pay.getPrjPrdPayDetailList()) {
                    //以租代购12期之后的租金
                    if (detail.getPayPd().intValue() > reduStartPd) {
                        after12LastRntAmt = DecimalUtils.add(after12LastRntAmt, detail.getRntAmt());
                    }
                }
                if (CollectionUtils.isNotEmpty(pay.getSubFeeAmtTotalList())) {
                    for (PrjPrdPaySchDVO paySchDVO : pay.getSubFeeAmtTotalList()) {
                        paySchDVO.setFeeAmt(DecimalUtils.convertFenToYuan(paySchDVO.getFeeAmt().longValue()));
                    }
                }
            }
            List<SysDictionaryVO> settFeeTypCdListJSON = this.prjPrdPaySchMService.getSettFeeTypList();
            settPctList = this.prjPrdPaySchMService.selectSettPctList();

            view.addObject("pay", pay);
            view.addObject("cst", cst);
            view.addObject("prj", prj);
            view.addObject("dtl", dtl);
            view.addObject("showBk_oCIn", showBk_oCIn);
            view.addObject("isDetail_bk", isDetail_bk);
            view.addObject("showBk_oCOut", showBk_oCOut);
            view.addObject("editInto", editInto);
            view.addObject("editOut", editOut);
            view.addObject("confirm", confirm);
            view.addObject("subFeeAmtTotalList", JSON.toJSONString(null == pay.getSubFeeAmtTotalList() ? "" : pay.getSubFeeAmtTotalList()));
            view.addObject("listPage", JSON.toJSONString(listPage));
            view.addObject("feeListPage", JSON.toJSONString(feeListPage));
            view.addObject("paySchId", paySchId);
            view.addObject("settFeeTypCdListJSON", JSON.toJSONString(settFeeTypCdListJSON));
            view.addObject("optba", openTheBillAdd);
            view.addObject("optbf", openTheBillForFinance);
            view.addObject("optbd", openTheBillForDetail);
            view.addObject("procInstId", procInstId);
            view.addObject("settPctValue", settPctValue);
            view.addObject("extContAmt", extContAmt);
            view.addObject("reduAmt", reduAmt);
            view.addObject("yzdgFlag", yzdgFlag);
            view.addObject("settPctList", settPctList);
            view.addObject("after12LastRntAmt", after12LastRntAmt);
            view.addObject("fileAuth", request.getParameter("fileAuth"));
        } catch (BaseException ex) {
            BaseLogUtils.newLogger("结清流程中页面查询失败.").setBussinessId(paySchId).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
            throw ex;
        } catch (Exception ex) {
            BaseLogUtils.newLogger("结清流程中页面查询失败.").setBussinessId(paySchId).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
            throw ex;
        }
        return view;
    }

    /**
     * 显示正常结清预览页面
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/showSettlePage.do", method = {RequestMethod.GET})
    public ModelAndView showSettlePage(HttpServletRequest request) {
        BaseLogUtils.info(logger, "showSettlePage", "显示正常结清预览页面.", CurrentThreadContext.getCurrentUserName());
        String paySchId = request.getParameter("paySchId");// 我司支付表ID
        String payPd = request.getParameter("payPd");
        PrjBscInfoVO prj = null;
        PrjPrdPaySchMVO pay = null;
        CstBscInfoVO cst = null;
        ListPageVO<PrjPrdPrpsFeeDetailVO> listPage = null;
        ListPageVO<PrjPrdPaySchDVO> feeListPage = null;
        PrjPrdDtlVO dtl = null;
        ModelAndView view = new ModelAndView("project/prjprdquatprps/prjPrdPaySchMSettleDetailPage");
        try {
            if (StringUtils.isNotBlank(paySchId)) {
                pay = this.prjPrdPaySchMService.searchSettleData(Long.valueOf(paySchId), new Date(), Integer.valueOf(payPd));
                PrjPrdDtlQueryCondition qc = new PrjPrdDtlQueryCondition();
                qc.setPaySchId(pay.getWsPaySchId());
                List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(qc);
                if (CollectionUtils.isNotEmpty(dtlList)) {
                    dtl = dtlList.get(0);
                }
                if (null != pay) {
                    cst = this.cstBscInfoService.selectDetailById(pay.getCstId());
                    prj = this.prjBscInfoService.selectById(pay.getPrjId());
                }
            }
            if (CollectionUtils.isNotEmpty(pay.getPrjPrdPayDetailList())) {
                listPage = new ListPageVO<PrjPrdPrpsFeeDetailVO>(pay.getPrjPrdPayDetailList(), pay.getPrjPrdPayDetailList().size());
                pay.setPrjQuatPrpsPaySchPage(listPage);
            }
            if (CollectionUtils.isNotEmpty(pay.getFeeDetailList())) {
                List<PrjPrdPaySchDVO> list = new ArrayList<PrjPrdPaySchDVO>();
                for (PrjPrdPaySchDVO prjPrdPaySchDVO : pay.getFeeDetailList()) {
                    if (prjPrdPaySchDVO.getFeeClsCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_PRPS)) {
                        list.add(prjPrdPaySchDVO);
                    }
                }

                //首期款合计项
                PrjPrdPaySchDVO tatal = new PrjPrdPaySchDVO();
                tatal.setFeeTypCdNm("首期款合计");
                tatal.setFeeAmt(pay.getFirstPayAmt());
                tatal.setPaidUpAmt(pay.getTotalFirstPayAmt().longValue());
                list.add(tatal);
                feeListPage = new ListPageVO<PrjPrdPaySchDVO>(list, list.size());
                // feeListPage = new ListPageVO<PrjPrdPaySchDVO>(pay.getFeeDetailList(), pay.getFeeDetailList().size());
                pay.setFeeDetailListPage(feeListPage);
            }
            if (CollectionUtils.isNotEmpty(pay.getSubFeeAmtTotalList())) {
                for (PrjPrdPaySchDVO paySchDVO : pay.getSubFeeAmtTotalList()) {
                    paySchDVO.setFeeAmt(DecimalUtils.convertFenToYuan(paySchDVO.getFeeAmt().longValue()));
                }
            }
            List<SysDictionaryVO> settFeeTypCdListJSON = this.prjPrdPaySchMService.getSettFeeTypList();

            view.addObject("pay", pay);
            view.addObject("cst", cst);
            view.addObject("prj", prj);
            view.addObject("subFeeAmtTotalList", JSON.toJSONString(pay.getSubFeeAmtTotalList()));
            view.addObject("listPage", JSON.toJSONString(listPage));
            view.addObject("feeListPage", JSON.toJSONString(feeListPage));
            view.addObject("paySchId", pay.getId());// 返回已启用的支付表ID给页面
            view.addObject("dtl", dtl);
            view.addObject("settFeeTypCdListJSON", JSON.toJSONString(settFeeTypCdListJSON));
            view.addObject("model", "preview");// 代表结清申请预览
            // 发起结清按钮权限
            view.addObject("showStlBtn", prjPrdPaySchMService.settleAuthority(pay.getId()));
            return view;
        } catch (BaseException ex) {
            BaseLogUtils.newLogger("显示正常结清预览页面失败.").setBussinessId(paySchId).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
            throw ex;
        } catch (Exception ex) {
            BaseLogUtils.newLogger("显示正常结清预览页面失败.").setBussinessId(paySchId).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
            throw ex;
        }
    }

    /**
     * 结清添加费用项页面
     */
    @RequestMapping(value = "/settleAddFeePage.do", method = {RequestMethod.GET})
    public ModelAndView settleAddFeePage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "settleAddFeePage", "加载PrjPrdPaySchM列表页面.", CurrentThreadContext.getCurrentUserName());
        String paySchId = request.getParameter("paySchId");//支付表ID
        String isDetail = request.getParameter("isDetail");
        String isDetail_bk = request.getParameter("isDetail_bk");//标识是否详情_YAOXIURONG
        String showBk_oCIn = request.getParameter("showBk_oCIn");//加载我司收款账号维护页面
        String showBk_oCOut = request.getParameter("showBk_oCOut");//加载我司付款账号维护页面
        //如果为空 设置为1 使流程中每个节点都可以查看账户信息
        if (StringUtils.isEmpty(showBk_oCIn) && StringUtils.isEmpty(showBk_oCOut)) {
            showBk_oCIn = "1";
            showBk_oCOut = "1";
            isDetail_bk = "1";
        }

        String editInto = request.getParameter("editInto");//我司付款_维护收款账号
        String editOut = request.getParameter("editOut");//我司付款_维护付款账号
        String openTheBillAdd = request.getParameter("optba");//标识是否需要开票新增列表页面_FUJINGRUN
        String openTheBillForFinance = request.getParameter("optbf");//标识是否显示财务开票列表页面_FUJINGRUN
        String openTheBillForDetail = request.getParameter("optbd");//是否显示开票详细列表页面_FUJINGRUN
        String procInstId = request.getParameter("processInstanceId");//流程实例ID_FUJINGRUN
        String taskDefKey = request.getParameter("taskDefKey");// 例如：FLOW_00000001_063_001_001
        PrjBscInfoVO prj = null;
        PrjPrdPaySchMVO pay = null;
        CstBscInfoVO cst = null;
        ListPageVO<PrjPrdPrpsFeeDetailVO> listPage = null;
        ListPageVO<PrjPrdPaySchDVO> feeListPage = null;
        PrjPrdDtlVO dtl = null;
        Integer payPd = null;
        Date applyDate = null;
        ModelAndView view = new ModelAndView("project/prjprdquatprps/prjPrdPaySchMSettleAddFeePage");
        view.addObject("taskDefKey", taskDefKey);
        try {
            if (StringUtils.isNotBlank(paySchId)) {
                PrjStlMVO stlMVO = this.prjStlMService.selectByPaySchMId(Long.valueOf(paySchId), PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_CST);
                // 查找结清期数
                PrjPrdPaySchMVO schMVO = getSchMVO(procInstId, Long.valueOf(paySchId));
                payPd = schMVO.getStlPd();

                pay = this.prjPrdPaySchMService.searchSettleData(Long.valueOf(paySchId), null, payPd);
                if (null != pay) {
                    cst = this.cstBscInfoService.selectDetailById(pay.getCstId());
                    prj = this.prjBscInfoService.selectById(pay.getPrjId());
                    // 申请时间
                    applyDate = pay.getApplyDt();
                    if (null != stlMVO && null != applyDate && null != stlMVO.getStlStDt()
                            && org.apache.commons.lang3.time.DateUtils.isSameDay(applyDate, stlMVO.getStlStDt())) {
                        if (null != stlMVO.getRmS03ArTotAmt()) {
                            pay.setLastPrintAmt(stlMVO.getRmS03ArTotAmt() - (null == stlMVO.getStlOverdueS03Amt() ? 0 : stlMVO.getStlOverdueS03Amt()));
                        }
                        if (null != stlMVO.getRmS02ArTotAmt()) {
                            pay.setLastIntAmt(stlMVO.getRmS02ArTotAmt() - (null == stlMVO.getStlOverdueS02Amt() ? 0 : stlMVO.getStlOverdueS02Amt()));
                        }
                        if (null != stlMVO.getStlPenaltyAmt()) {
                            pay.setPenaltyAmt(stlMVO.getStlPenaltyAmt());
                        }
                        if (null != stlMVO.getStlOverdueAmt()) {
                            pay.setOverdueAmt(stlMVO.getStlOverdueAmt());
                        }
                        if (null != stlMVO.getStlAmt()) {
                            pay.setStlAmt(stlMVO.getStlAmt().longValue());
                            pay.setFinalPayAmt(stlMVO.getStlAmt());
                            pay.setTotalSettAmt(stlMVO.getStlAmt());
                        }
                    }
                }
                PrjPrdDtlQueryCondition qc = new PrjPrdDtlQueryCondition();
                qc.setPaySchId(pay.getWsPaySchId());// 我司支付表ID查询DTL
                List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(qc);
                if (CollectionUtils.isNotEmpty(dtlList)) {
                    dtl = dtlList.get(0);
                }
            }
            if (CollectionUtils.isNotEmpty(pay.getPrjPrdPayDetailList())) {
                listPage = new ListPageVO<PrjPrdPrpsFeeDetailVO>(pay.getPrjPrdPayDetailList(), pay.getPrjPrdPayDetailList().size());
                pay.setPrjQuatPrpsPaySchPage(listPage);
            }
            if (CollectionUtils.isNotEmpty(pay.getFeeDetailList())) {
                List<PrjPrdPaySchDVO> list = new ArrayList<PrjPrdPaySchDVO>();
                for (PrjPrdPaySchDVO prjPrdPaySchDVO : pay.getFeeDetailList()) {
                    if (prjPrdPaySchDVO.getFeeClsCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_PRPS)) {
                        list.add(prjPrdPaySchDVO);
                    }
                }
                //首期款合计项
                PrjPrdPaySchDVO tatal = new PrjPrdPaySchDVO();
                tatal.setFeeTypCdNm("首期款合计");
                tatal.setFeeAmt(pay.getFirstPayAmt());
                tatal.setPaidUpAmt(pay.getTotalFirstPayAmt().longValue());
                list.add(tatal);
                feeListPage = new ListPageVO<PrjPrdPaySchDVO>(list, list.size());
                pay.setFeeDetailListPage(feeListPage);
            }
            if (CollectionUtils.isNotEmpty(pay.getSubFeeAmtTotalList())) {
                for (PrjPrdPaySchDVO paySchDVO : pay.getSubFeeAmtTotalList()) {
                    paySchDVO.setFeeAmt(DecimalUtils.convertFenToYuan(paySchDVO.getFeeAmt().longValue()));
                }
            }

            //费用类型
            List<SysDictionaryVO> settFeeTypCdListJSON = this.prjPrdPaySchMService.getSettFeeTypList();

            view.addObject("settFeeTypCdListJSON", JSON.toJSONString(settFeeTypCdListJSON));
            view.addObject("settleWay", "正常结清");
            view.addObject("pay", pay);
            view.addObject("cst", cst);
            view.addObject("prj", prj);
            view.addObject("listPage", JSON.toJSONString(listPage));
            view.addObject("feeListPage", JSON.toJSONString(feeListPage));
            view.addObject("subFeeAmtTotalList", JSON.toJSONString(pay.getSubFeeAmtTotalList()));
            view.addObject("paySchId", paySchId);
            view.addObject("dtl", dtl);
            view.addObject("isDetail", StringUtils.isEmpty(isDetail) ? "0" : isDetail);
            view.addObject("showBk_oCIn", showBk_oCIn);
            view.addObject("showBk_oCOut", showBk_oCOut);
            view.addObject("editInto", editInto);
            view.addObject("editOut", editOut);
            view.addObject("isDetail_bk", isDetail_bk);
            view.addObject("optba", openTheBillAdd);
            view.addObject("optbf", openTheBillForFinance);
            view.addObject("optbd", openTheBillForDetail);
            view.addObject("procInstId", procInstId);
            view.addObject("fileAuth", request.getParameter("fileAuth"));

            //重卡正常结清-查询绑定资金数据
            BaseLogUtils.info(logger, "settleAddFeePage", "settleAddFeePage重卡正常结清-查询绑定资金数据开始，数据：" + JSON.toJSONString(view));
            view = findBindFundData(request, view, Long.parseLong(paySchId), pay.getWsPaySchId());
            BaseLogUtils.info(logger, "settleAddFeePage", "settleAddFeePage重卡正常结清-查询绑定资金数据结束，数据：" + JSON.toJSONString(view));
            view.addObject("wsPaySchId", pay.getWsPaySchId());
        } catch (BaseException ex) {
            BaseLogUtils.newLogger("结清添加费用项页面查询失败.").setBussinessId(paySchId).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
        } catch (Exception ex) {
            BaseLogUtils.newLogger("结清添加费用项页面查询失败.").setBussinessId(paySchId).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
        }
        return view;
    }

    /**
     * 查询绑定资金数据
     * @param request
     * @param mav
     * @param paySchId    启用的支付表ID
     * @param wsPaySchId  我司支付表ID
     * @return
     */
    public ModelAndView findBindFundData(HttpServletRequest request, ModelAndView mav, Long paySchId, Long wsPaySchId) {
        BaseLogUtils.info(logger, "findBindFundData", "findBindFundData查询绑定资金数据开始");
        this.prepare(request, mav);
        String bizTyp = request.getParameter("bizTyp");//业务类型 3
        mav.addObject("bizTyp", bizTyp);
        Long dataId = paySchId;//业务主键
        if (dataId == null || StringUtils.isEmpty(bizTyp)) {
            BaseLogUtils.info(logger, "findBindFundData", "findBindFundData查询绑定资金数据，业务主键或类型为空.", CurrentThreadContext.getCurrentUserName());
            return mav;
        }

        String isMdfPaySch = request.getParameter("isMdfPaySch");
        String stlDtFlag = request.getParameter("stlDtFlag");//1.显示结清时间维护 2.不显示结清时间维护
        //查询支付表信息
        PrjPrdPaySchMVO paySchMVO = this.prjPrdPaySchMService.selectById(dataId);
        if (paySchMVO == null) {
            BaseLogUtils.info(logger, "findBindFundData", "findBindFundData,未找到支付表[" + dataId + "]信息.", CurrentThreadContext.getCurrentUserName());
            return mav;
        }
        //查询项目信息
        PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(paySchMVO.getPrjId());
        if (prjBscInfoVO == null) {
            BaseLogUtils.info(logger, "findBindFundData", "findBindFundData,未找到支付表[" + dataId + "]对应项目信息.", CurrentThreadContext.getCurrentUserName());
            return mav;
        }
        if (StringUtils.isNotBlank(stlDtFlag) && "2".equals(isMdfPaySch)) {
            mav.addObject("stlDtlFlag", "2");//2.不显示结清时间维护
        } else {
            mav.addObject("stlDtlFlag", "1");//1.显示结清时间维护
        }

        BaseLogUtils.info(logger, "findBindFundData", "到结清录入来款页面");
        CapFundVO fundVO = new CapFundVO();//来款信息
        fundVO.setRelationPayId(dataId);//资金管理关联业务ID
        fundVO.setIdentifyOperator(CurrentThreadContext.getCurrentUserId());//认款人ID
        fundVO.setIdentifyOperatorNm(CurrentThreadContext.getCurrentUserName());//认款人名称
        fundVO.setIdentifyTime(new Date());//认款时间 add时会修改
        //默认财务收款账户、账号
        fundVO.setAcceptName(InsuranceConstant.CODE_FC_ACCEPT_ACCOUNT_NM);//收款账户
        fundVO.setAcceptCode(InsuranceConstant.CODE_FC_ACCEPT_ACCOUNT_CD);//收款账号
        fundVO.setPaySchNo(paySchMVO.getPaySchNo());

        //查询客户名称，客户ID,所属事业部
        fundVO.setCstId(paySchMVO.getCstId());
        fundVO.setCstNm(prjBscInfoVO.getCstNm());
        fundVO.setFundBelongOrgCd(prjBscInfoVO.getBuOrgCd());
        fundVO.setComeName(prjBscInfoVO.getCstNm());

        //查询待核销支付表明细列表 支付表号、客户ID、期次、费用类型
        //mav.addObject("paySchId", paySchMVO.getId());
        mav.addObject("cstId", fundVO.getCstId());

        //交易日期与实际到账日期默认流程发起时间
        Date flowStartTm = this.capFundService.getFlowStartTime(dataId, bizTyp);
        if (null != flowStartTm) {
            fundVO.setAcceptDate(DateUtils.formatDate(flowStartTm, DateUtils.YYYY_MM_DD));
            fundVO.setAcceptActualDate(DateUtils.formatDate(flowStartTm, DateUtils.YYYY_MM_DD));
            fundVO.setAcceptDates(DateUtils.formatDateToString(fundVO.getAcceptDate(), DateUtils.YYYY_MM_DD));
            fundVO.setAcceptActualDates(DateUtils.formatDateToString(fundVO.getAcceptActualDate(), DateUtils.YYYY_MM_DD));
        }

        //结清时间
        PrjPrdDtlQueryCondition dtlQueryCondition = new PrjPrdDtlQueryCondition();
        dtlQueryCondition.setPaySchId(wsPaySchId);// 我司支付表ID
        List<PrjPrdDtlVO> prdDtlVOList = this.prjPrdDtlService.selectList(dtlQueryCondition);
        if (CollectionUtils.isNotEmpty(prdDtlVOList)) {
            PrjPrdDtlVO prjPrdDtlVO = prdDtlVOList.get(0);
            if (null != prjPrdDtlVO.getStlDt()) {
                mav.addObject("stlDt", DateUtils.formatDateToString(prjPrdDtlVO.getStlDt(), DateUtils.YYYY_MM_DD));
            }
            mav.addObject("prjPrdDtlId", prjPrdDtlVO.getId());
        }
        mav.addObject("capFundVO", fundVO);
        BaseLogUtils.info(logger, "findBindFundData", "findBindFundData查询绑定资金数据结束");
        return mav;
    }

    /**
     * 查询支付表主表信息
     * 在支付表主表中查找结清期数，如果没有查找流程发起的期数信息
     *
     * @param procInstId
     * @param paySchId
     * @return
     */
    private PrjPrdPaySchMVO getSchMVO(String procInstId, Long paySchId) {
        Integer payPd = null;
        Date applyDate = null;
        PrjPrdPaySchMVO schMVO = this.prjPrdPaySchMService.selectById(paySchId);
        if (null != schMVO && null != schMVO.getStlPd()) {
            payPd = schMVO.getStlPd();
        }
        if (null == schMVO) {
            schMVO = new PrjPrdPaySchMVO();
        }
        if (null == payPd) {
            SysFlowSHQueryCondition flowQc = new SysFlowSHQueryCondition();
            if (StringUtils.isNotBlank(procInstId)) {
                flowQc.setpInstId(procInstId);
            } else {
                List<Long> idList = new ArrayList<Long>();
                idList.add(paySchId);
                flowQc.setDataIdList(idList);
            }
            flowQc.setWordsInTheTable(PrjBscInfoConstant.PRJ_FLOW_S_H_PRJ);
            flowQc.setSysCd(CurrentThreadContext.getCurrentSysCd());
            flowQc.setStatus(BaseConstant.IS_YESNO_YES);
            List<String> busTypList = new ArrayList<String>();
            busTypList.add(FlowConstant.FLOW_MODEL_TYP_SETTLE_NORMAL);
            busTypList.add(FlowConstant.FLOW_MODEL_TYP_SETTLE_ADVANCE);
            flowQc.setBusTypList(busTypList);
            List<SysFlowSHDTO> flowSHList = this.flowQueryApiService.searchFlowSHList(flowQc);
            if (CollectionUtils.isNotEmpty(flowSHList)) {
                applyDate = flowSHList.get(0).getpCrtTm();
            }

            PrjPrdPaySchDQueryCondition payQc = new PrjPrdPaySchDQueryCondition();
            payQc.setPaySchId(paySchId);
            payQc.setSortName("PAY_PD");
            payQc.setSortOrder("ASC");
            payQc.setCurrentDt(applyDate);
            payQc.setFeeTypCd(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_RNT_PRICE);
            List<PrjPrdPaySchDVO> payList = this.prjPrdPaySchDService.searchList(payQc);
            if (CollectionUtils.isNotEmpty(payList)) {
                payPd = payList.get(0).getPayPd();
            } else {
                payPd = 0;
            }
            schMVO.setStlPd(payPd);
            schMVO.setApplyDt(applyDate);
        }
        return schMVO;
    }

    /**
     * 正常结清流程中查看页面
     */
    @RequestMapping(value = "/settleFlowPage.do", method = {RequestMethod.GET})
    public ModelAndView settleFlowPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "settleFlowPage", "加载正常结清流程中查看页面.", CurrentThreadContext.getCurrentUserName());
        String paySchId = request.getParameter("paySchId");//支付表ID
        String taskDefKey = request.getParameter("taskDefKey");
        String isDetail_bk = request.getParameter("isDetail_bk");//标识是否详情_YAOXIURONG
        String showBk_oCIn = request.getParameter("showBk_oCIn");//加载我司收款账号维护页面
        String showBk_oCOut = request.getParameter("showBk_oCOut");//加载我司付款账号维护页面
        String confirm = request.getParameter("confirm");// 确认我司付款账户 (created by REQ-9253 自动退款)
        //如果为空 设置为1 使流程中每个节点都可以查看账户信息
        if (StringUtils.isEmpty(showBk_oCIn) && StringUtils.isEmpty(showBk_oCOut)) {
            showBk_oCIn = "1";
            showBk_oCOut = "1";
            isDetail_bk = "1";
        }

        String editInto = request.getParameter("editInto");//我司付款_维护收款账号
        String editOut = request.getParameter("editOut");//我司付款_维护付款账号
        String openTheBillAdd = request.getParameter("optba");//标识是否需要开票新增列表页面_FUJINGRUN
        String openTheBillForFinance = request.getParameter("optbf");//标识是否显示财务开票列表页面_FUJINGRUN
        String openTheBillForDetail = request.getParameter("optbd");//是否显示开票详细列表页面_FUJINGRUN
        String procInstId = request.getParameter("processInstanceId");//流程实例ID_FUJINGRUN
        PrjBscInfoVO prj = null;
        PrjPrdPaySchMVO pay = null;
        CstBscInfoVO cst = null;
        ListPageVO<PrjPrdPrpsFeeDetailVO> listPage = null;
        ListPageVO<PrjPrdPaySchDVO> feeListPage = null;
        PrjPrdDtlVO dtl = null;
        Integer payPd = null;
        Date applyDate = null;
        ModelAndView view = new ModelAndView("project/prjprdquatprps/prjPrdPaySchMSettFlowPage");
        try {
            if (StringUtils.isNotBlank(paySchId)) {
                PrjStlMVO stlMVO = this.prjStlMService.selectByPaySchMId(Long.valueOf(paySchId), PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_CST);

                // 查找结清期数
                PrjPrdPaySchMVO schMVO = getSchMVO(procInstId, Long.valueOf(paySchId));
                payPd = schMVO.getStlPd();

                pay = this.prjPrdPaySchMService.searchSettleData(Long.valueOf(paySchId), null, payPd);
                if (null != pay) {
                    cst = this.cstBscInfoService.selectDetailById(pay.getCstId());
                    prj = this.prjBscInfoService.selectById(pay.getPrjId());
                    PrjPrdDtlQueryCondition qc = new PrjPrdDtlQueryCondition();
                    qc.setPaySchId(pay.getWsPaySchId());
                    List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(qc);
                    if (CollectionUtils.isNotEmpty(dtlList)) {
                        dtl = dtlList.get(0);
                    }
                    // 申请时间
                    applyDate = pay.getApplyDt();
                    if (null != stlMVO && null != applyDate && null != stlMVO.getStlStDt()
                            && org.apache.commons.lang3.time.DateUtils.isSameDay(applyDate, stlMVO.getStlStDt())) {
                        if (null != stlMVO.getRmS03ArTotAmt()) {
                            pay.setLastPrintAmt(stlMVO.getRmS03ArTotAmt() - (null == stlMVO.getStlOverdueS03Amt() ? 0 : stlMVO.getStlOverdueS03Amt()));
                        }
                        if (null != stlMVO.getRmS02ArTotAmt()) {
                            pay.setLastIntAmt(stlMVO.getRmS02ArTotAmt() - (null == stlMVO.getStlOverdueS02Amt() ? 0 : stlMVO.getStlOverdueS02Amt()));
                        }

                        if (null != stlMVO.getStlPenaltyAmt()) {
                            pay.setPenaltyAmt(stlMVO.getStlPenaltyAmt());
                        }
                        if (null != stlMVO.getStlOverdueAmt()) {
                            pay.setOverdueAmt(stlMVO.getStlOverdueAmt());
                        }
                        if (null != stlMVO.getStlAmt()) {
                            pay.setStlAmt(stlMVO.getStlAmt().longValue());
                            pay.setFinalPayAmt(stlMVO.getStlAmt());
                            pay.setTotalSettAmt(stlMVO.getStlAmt());
                        }
                    }
                }

                if (CollectionUtils.isNotEmpty(pay.getPrjPrdPayDetailList())) {
                    listPage = new ListPageVO<PrjPrdPrpsFeeDetailVO>(pay.getPrjPrdPayDetailList(), pay.getPrjPrdPayDetailList().size());
                    pay.setPrjQuatPrpsPaySchPage(listPage);
                }
                if (CollectionUtils.isNotEmpty(pay.getFeeDetailList())) {
                    List<PrjPrdPaySchDVO> list = new ArrayList<PrjPrdPaySchDVO>();
                    for (PrjPrdPaySchDVO prjPrdPaySchDVO : pay.getFeeDetailList()) {
                        if (prjPrdPaySchDVO.getFeeClsCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_PRPS)) {
                            list.add(prjPrdPaySchDVO);
                        }
                    }
                    //首期款合计项
                    PrjPrdPaySchDVO tatal = new PrjPrdPaySchDVO();
                    tatal.setFeeTypCdNm("首期款合计");
                    tatal.setFeeAmt(pay.getFirstPayAmt());
                    tatal.setPaidUpAmt(pay.getTotalFirstPayAmt().longValue());
                    list.add(tatal);
                    feeListPage = new ListPageVO<PrjPrdPaySchDVO>(list, list.size());
                    pay.setFeeDetailListPage(feeListPage);
                }
                if (CollectionUtils.isNotEmpty(pay.getSubFeeAmtTotalList())) {
                    for (PrjPrdPaySchDVO paySchDVO : pay.getSubFeeAmtTotalList()) {
                        paySchDVO.setFeeAmt(DecimalUtils.convertFenToYuan(paySchDVO.getFeeAmt().longValue()));
                    }
                }

            }

            //费用类型
            List<SysDictionaryVO> settFeeTypCdListJSON = this.prjPrdPaySchMService.getSettFeeTypList();
            view.addObject("settFeeTypCdListJSON", JSON.toJSONString(settFeeTypCdListJSON));
            view.addObject("settleWay", "正常结清");
            view.addObject("pay", pay);
            view.addObject("cst", cst);
            view.addObject("prj", prj);
            view.addObject("showBk_oCIn", showBk_oCIn);
            view.addObject("showBk_oCOut", showBk_oCOut);
            view.addObject("editInto", editInto);
            view.addObject("editOut", editOut);
            view.addObject("isDetail", "1");
            view.addObject("isDetail_bk", isDetail_bk);
            view.addObject("listPage", JSON.toJSONString(listPage));
            view.addObject("feeListPage", JSON.toJSONString(feeListPage));
            view.addObject("subFeeAmtTotalList", JSON.toJSONString(pay.getSubFeeAmtTotalList()));
            view.addObject("paySchId", paySchId);
            view.addObject("optba", openTheBillAdd);
            view.addObject("optbf", openTheBillForFinance);
            view.addObject("optbd", openTheBillForDetail);
            view.addObject("procInstId", procInstId);
            view.addObject("dtl", dtl);
            view.addObject("taskDefKey", taskDefKey);
            view.addObject("confirm", confirm);
            view.addObject("fileAuth", request.getParameter("fileAuth"));
            return view;
        } catch (BaseException ex) {
            BaseLogUtils.newLogger("正常结清流程中查看页面查询失败.").setBussinessId(paySchId).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
            throw ex;
        } catch (Exception ex) {
            BaseLogUtils.newLogger("正常结清流程中查看页面查询失败.").setBussinessId(paySchId).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
            throw ex;
        }
    }

    /**
     * 显示乘用车提前结清添加费用项页面
     */
    @RequestMapping(value = "/addCarPreSettleFeePage.do", method = {RequestMethod.GET})
    public ModelAndView addCarPreSettleFeePage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("显示提前结清详情页面." + CurrentThreadContext.getCurrentUserName()).info();
        String paySchId = request.getParameter("paySchId");//支付表ID
        String isDetail = request.getParameter("isDetail");
        String taskDefKey = request.getParameter("taskDefKey");
        Integer payPd = null;//提前结清时结清期数
        PrjBscInfoVO prj = null;
        PrjPrdPaySchMVO pay = null;
        //CstBscInfoVO cst = null;
        ListPageVO<PrjPrdPrpsFeeDetailVO> listPage = null;
        ListPageVO<PrjPrdPaySchDVO> feeListPage = null;
        PrjPrdDtlVO dtl = null;
        //Date applyDate = null;
        ModelAndView view = new ModelAndView("project/prjprdquatprps/prjPrdPaySchMCarPreSettleAddFeePage");
        try {
            if (StringUtils.isNotBlank(paySchId)) {
                PrjStlMVO stlMVO = this.prjStlMService.selectByPaySchMId(Long.valueOf(paySchId), PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_CST);

                // 查找结清期数
                PrjPrdPaySchMVO schMVO = getSchMVO("", Long.valueOf(paySchId));
                payPd = schMVO.getStlPd();

                pay = this.prjPrdPaySchMService.searchCarPreSettleData(Long.valueOf(paySchId), null, Integer.valueOf(payPd));
                dtl = pay.getDtlVO();
                if (dtl == null) {
                    PrjPrdDtlQueryCondition qc = new PrjPrdDtlQueryCondition();
                    qc.setPaySchId(pay.getWsPaySchId());
                    List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(qc);
                    if (CollectionUtils.isNotEmpty(dtlList)) {
                        dtl = dtlList.get(0);
                    }
                }
                if (null != pay) {
                    //cst = this.cstBscInfoService.selectDetailById(pay.getCstId());
                    prj = this.prjBscInfoService.selectById(pay.getPrjId());
                    if (null != stlMVO) {
                        if (null != stlMVO.getA6RmS03Amt() && stlMVO.getA6RmS03Amt().compareTo(0d) != 0) {
                            pay.setLastPrintAmt(stlMVO.getA6RmS03Amt());
                        }
                        if (null != stlMVO.getNoPaidS01Amt() && stlMVO.getNoPaidS01Amt().compareTo(0d) != 0) {
                            pay.setLastRntAmt(stlMVO.getNoPaidS01Amt());
                        }
                        if (null != stlMVO.getRmS02ArTotAmt()) {
                            pay.setLastIntAmt(stlMVO.getRmS02ArTotAmt() - (null == stlMVO.getStlOverdueS02Amt() ? 0 : stlMVO.getStlOverdueS02Amt()));
                        }
                        if (null != stlMVO.getStlPenaltyAmt()) {
                            pay.setPenaltyAmt(stlMVO.getStlPenaltyAmt());
                        }
                        if (null != stlMVO.getStlOverdueAmt()) {
                            pay.setOverdueAmt(stlMVO.getStlOverdueAmt());
                        }
                        if (null != stlMVO.getStlAmt()) {
                            pay.setStlAmt(stlMVO.getStlAmt().longValue());
                            pay.setFinalPayAmt(stlMVO.getStlAmt());
                            pay.setTotalSettAmt(stlMVO.getStlAmt());
                        }
                    }
                }
                if (CollectionUtils.isNotEmpty(pay.getPrjPrdPayDetailList())) {
                    List<PrjPrdPrpsFeeDetailVO> feeList = null;
                    double totalRnt = 0d;//租金
                    double totalPrint = 0d;//本金
                    double totalInt = 0d;//利息
                    double actTotalRnt = 0d;//实际剩余租金
                    double actTotalPrint = 0d;//实际本金
                    double actTotalInt = 0d;//实际利息
                    double tmpInt = 0d;//6期之前的利息
                    if (payPd != 0) {
                        //查询流程中临时状态的期数
                        Integer payPdFlow = null;
                        List<PrjPrdPaySchDVO> list = this.prjPrdPaySchDService.selectPaySchByDelStatusAndPaySchId(Long.valueOf(paySchId), PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                        if (CollectionUtils.isNotEmpty(list)) {
                            payPdFlow = list.get(0).getPayPd();
                            feeList = new ArrayList<PrjPrdPrpsFeeDetailVO>();
                            for (PrjPrdPaySchDVO prjPrdPaySchDVO : pay.getPrjPrdPaySchDList()) {
                                double arAmt = DecimalUtils.convertFenToYuan(prjPrdPaySchDVO.getArAmt());
                                if (null != payPdFlow && prjPrdPaySchDVO.getPayPd() >= payPdFlow) {
                                    if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_RNT_PRICE)) {
                                        actTotalRnt = DecimalUtils.add(actTotalRnt, arAmt);
                                    }
                                    if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_PRINT_PRICE)) {
                                        actTotalPrint = DecimalUtils.add(actTotalPrint, arAmt);
                                    }
                                    if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_INT_PRICE)) {
                                        actTotalInt = DecimalUtils.add(actTotalInt, arAmt);
                                    }
                                }
                                if (prjPrdPaySchDVO.getPayPd().doubleValue() <= 6 && prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_INT_PRICE)) {
                                    if (prjPrdPaySchDVO.getPayPd().doubleValue() >= payPdFlow) {
                                        tmpInt = DecimalUtils.add(tmpInt, arAmt);
                                    }
                                }
                            }
                            for (PrjPrdPrpsFeeDetailVO payDetail : pay.getPrjPrdPayDetailList()) {
                                if (payDetail.getPayPd().intValue() < Integer.valueOf(payPdFlow).intValue()) {
                                    totalRnt = DecimalUtils.add(totalRnt, payDetail.getRntAmt());
                                    totalPrint = DecimalUtils.add(totalPrint, payDetail.getPrinAmt());
                                    totalInt = DecimalUtils.add(totalInt, payDetail.getIntAmt());
                                    feeList.add(payDetail);
                                }
                                if (null != stlMVO) {
                                    if (payDetail.getPayPd().intValue() == Integer.valueOf(payPdFlow).intValue()) {
                                        payDetail.setRntAmt(stlMVO.getRmS01ArTotAmt());
                                        payDetail.setPrinAmt(stlMVO.getRmS03ArTotAmt());
                                        payDetail.setIntAmt(stlMVO.getRmS02ArTotAmt());
                                        payDetail.setRemPrinAmt(0d);
                                        payDetail.setIsDel(PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                                        feeList.add(payDetail);
                                    }
                                } else {
                                    if (payDetail.getPayPd().intValue() == Integer.valueOf(payPdFlow).intValue()) {
                                        //提前还款剩余的期次为支付表实际剩余的租金、本金、利息
                                        payDetail.setRntAmt(actTotalPrint + tmpInt);
                                        payDetail.setPrinAmt(actTotalPrint);
                                        payDetail.setIntAmt(tmpInt);
                                        payDetail.setRemPrinAmt(0d);
                                        payDetail.setIsDel(PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                                        feeList.add(payDetail);
                                    }
                                }
                            }
                        } else {
                            feeList = pay.getPrjPrdPayDetailList();
                        }
                    } else {
                        feeList = pay.getPrjPrdPayDetailList();
                    }
                    listPage = new ListPageVO<PrjPrdPrpsFeeDetailVO>(feeList, feeList.size());
                    pay.setPrjQuatPrpsPaySchPage(listPage);
                }

                if (CollectionUtils.isNotEmpty(pay.getFeeDetailList())) {
                    List<PrjPrdPaySchDVO> list = new ArrayList<PrjPrdPaySchDVO>();
                    for (PrjPrdPaySchDVO prjPrdPaySchDVO : pay.getFeeDetailList()) {
                        if (prjPrdPaySchDVO.getFeeClsCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_PRPS) && !(prjPrdPaySchDVO.getCntWayCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_CONT))) {
                            list.add(prjPrdPaySchDVO);
                        }
                    }
                    //首期款合计项
                    PrjPrdPaySchDVO tatal = new PrjPrdPaySchDVO();
                    tatal.setFeeTypCdNm("首期款合计");
                    tatal.setFeeAmt(pay.getFirstPayAmt());
                    tatal.setPaidUpAmt(pay.getTotalFirstPayAmt().longValue());
                    list.add(tatal);
                    feeListPage = new ListPageVO<PrjPrdPaySchDVO>(list, list.size());
                    pay.setFeeDetailListPage(feeListPage);
                }
                if (CollectionUtils.isNotEmpty(pay.getSubFeeAmtTotalList())) {
                    for (PrjPrdPaySchDVO paySchDVO : pay.getSubFeeAmtTotalList()) {
                        paySchDVO.setFeeAmt(DecimalUtils.convertFenToYuan(paySchDVO.getFeeAmt().longValue()));
                    }
                }
            }
            ListPageVO<PrjPrdPaySchDVO> settListPage = new ListPageVO<PrjPrdPaySchDVO>(pay.getSettFeeAmtList(), pay.getSettFeeAmtList().size());
            //费用类型
            List<SysDictionaryVO> settFeeTypCdListJSON = this.prjPrdPaySchMService.getSettFeeTypList();

            view.addObject("pay", pay);
            //view.addObject("cst", cst);
            view.addObject("prj", prj);
            view.addObject("dtl", dtl);
            view.addObject("subFeeAmtTotalList", JSON.toJSONString(pay.getSubFeeAmtTotalList()));
            view.addObject("listPage", JSON.toJSONString(listPage));
            view.addObject("feeListPage", JSON.toJSONString(feeListPage));
            view.addObject("paySchId", paySchId);
            view.addObject("settFeeTypCdListJSON", JSON.toJSONString(settFeeTypCdListJSON));
            view.addObject("isDetail", isDetail);
            view.addObject("settFeeList", JSON.toJSONString(settListPage));
            view.addObject("taskDefKey", taskDefKey);
            view.addObject("wsPaySchId", pay.getWsPaySchId());
            view.addObject("fileAuth", request.getParameter("fileAuth"));
        } catch (BaseException ex) {
            BaseLogUtils.newLogger("结清添加费用项页面查询失败.").setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
            throw ex;
        } catch (Exception ex) {
            BaseLogUtils.newLogger("结清添加费用项页面查询失败.").setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
            throw ex;
        }
        return view;
    }

    /**
     * 显示乘用车提前结流程中页面
     */
    @RequestMapping(value = "/carPreSettleFlowPage.do", method = {RequestMethod.GET})
    public ModelAndView carPreSettleFlowPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "carPreSettleFlowPage", "显示提前结清流程中详情页面.", CurrentThreadContext.getCurrentUserName());
        String paySchId = request.getParameter("paySchId");//支付表ID
        String isDetail_bk = request.getParameter("isDetail_bk");//标识是否详情_YAOXIURONG
        String showBk_oCIn = request.getParameter("showBk_oCIn");//加载我司收款账号维护页面
        String showBk_oCOut = request.getParameter("showBk_oCOut");//加载我司付款账号维护页面
        String editInto = request.getParameter("editInto");//我司付款_维护收款账号
        String editOut = request.getParameter("editOut");//我司付款_维护付款账号
        String confirm = request.getParameter("confirm");
        String openTheBillAdd = request.getParameter("optba");//标识是否需要开票新增列表页面_FUJINGRUN
        String openTheBillForFinance = request.getParameter("optbf");//标识是否显示财务开票列表页面_FUJINGRUN
        String openTheBillForDetail = request.getParameter("optbd");//是否显示开票详细列表页面_FUJINGRUN
        String procInstId = request.getParameter("processInstanceId");//流程实例ID_FUJINGRUN
        Integer payPd = null;//提前结清时结清期数
        PrjBscInfoVO prj = null;
        PrjPrdPaySchMVO pay = null;
        //CstBscInfoVO cst = null;
        ListPageVO<PrjPrdPrpsFeeDetailVO> listPage = null;
        ListPageVO<PrjPrdPaySchDVO> feeListPage = null;
        PrjPrdDtlVO dtl = null;
        //Date applyDate = null;
        //double discountAmt = 0d;
        double breachAmt = 0d;
        ModelAndView view = new ModelAndView("project/prjprdquatprps/prjPrdPaySchMCarPreSettleFlowPage");
        try {
            if (StringUtils.isNotBlank(paySchId)) {
                // 查找结清期数
                PrjPrdPaySchMVO schMVO = getSchMVO(procInstId, Long.valueOf(paySchId));
                payPd = schMVO.getStlPd();

                PrjStlMVO stlMVO = this.prjStlMService.selectByPaySchMId(Long.valueOf(paySchId), PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_CST);
                pay = this.prjPrdPaySchMService.searchCarPreSettleData(Long.valueOf(paySchId), null, Integer.valueOf(payPd));
                List<PrjPrdPaySchDVO> payFeeList = pay.getFeeDetailList();
                if (CollectionUtils.isNotEmpty(payFeeList)) {
                    for (PrjPrdPaySchDVO prjPrdPaySchDDTO : payFeeList) {
                        if (prjPrdPaySchDDTO.getFeeClsCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_SETT) && null != prjPrdPaySchDDTO.getIsSysDef() && prjPrdPaySchDDTO.getIsSysDef().equals(BaseConstant.IS_YESNO_YES)) {
                            if (prjPrdPaySchDDTO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_103)) {
                                breachAmt = prjPrdPaySchDDTO.getFeeAmt();
                            }
                        }
                    }
                }
                if (null != stlMVO) {
                    if (null != stlMVO.getA6RmS03Amt() && stlMVO.getA6RmS03Amt().compareTo(0d) != 0) {
                        pay.setLastPrintAmt(stlMVO.getA6RmS03Amt());
                    }

                    if (null != stlMVO.getNoPaidS01Amt() && stlMVO.getNoPaidS01Amt().compareTo(0d) != 0) {
                        pay.setLastRntAmt(stlMVO.getNoPaidS01Amt());
                    }
                    if (null != stlMVO.getRmS02ArTotAmt()) {
                        pay.setLastIntAmt(stlMVO.getRmS02ArTotAmt() - (null == stlMVO.getStlOverdueS02Amt() ? 0 : stlMVO.getStlOverdueS02Amt()));
                    }

                    if (null != stlMVO.getStlPenaltyAmt()) {
                        pay.setPenaltyAmt(stlMVO.getStlPenaltyAmt());
                    }
                    if (null != stlMVO.getStlOverdueAmt()) {
                        pay.setOverdueAmt(stlMVO.getStlOverdueAmt());
                    }
                    if (null != stlMVO.getStlAmt()) {
                        pay.setStlAmt(stlMVO.getStlAmt().longValue());
                        pay.setFinalPayAmt(stlMVO.getStlAmt());
                        pay.setTotalSettAmt(stlMVO.getStlAmt());
                    }
                }
                pay.setBreachAmt(breachAmt);
                dtl = pay.getDtlVO();
                if (dtl == null) {
                    PrjPrdDtlQueryCondition qc = new PrjPrdDtlQueryCondition();
                    qc.setPaySchId(pay.getWsPaySchId());
                    List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(qc);
                    if (CollectionUtils.isNotEmpty(dtlList)) {
                        dtl = dtlList.get(0);
                    }
                }
                if (null != pay) {
                    //cst = this.cstBscInfoService.selectDetailById(pay.getCstId());
                    prj = this.prjBscInfoService.selectById(pay.getPrjId());
                }

                if (CollectionUtils.isNotEmpty(pay.getPrjPrdPayDetailList())) {
                    List<PrjPrdPrpsFeeDetailVO> feeList = null;
                    double totalRnt = 0d;//租金
                    double totalPrint = 0d;//本金
                    double totalInt = 0d;//利息
                    double actTotalRnt = 0d;//实际剩余租金
                    double actTotalPrint = 0d;//实际本金
                    double actTotalInt = 0d;//实际利息
                    double tmpInt = 0d;//6期之前的利息
                    if (payPd != 0) {
                        //查询流程中临时状态的期数
                        Integer payPdFlow = null;
                        List<PrjPrdPaySchDVO> list = this.prjPrdPaySchDService.selectPaySchByDelStatusAndPaySchId(Long.valueOf(paySchId), PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                        if (CollectionUtils.isNotEmpty(list)) {
                            payPdFlow = list.get(0).getPayPd();
                            feeList = new ArrayList<PrjPrdPrpsFeeDetailVO>();
                            for (PrjPrdPaySchDVO prjPrdPaySchDVO : pay.getPrjPrdPaySchDList()) {
                                double arAmt = DecimalUtils.convertFenToYuan(prjPrdPaySchDVO.getArAmt());
                                if (null != payPdFlow && prjPrdPaySchDVO.getPayPd() >= payPdFlow) {
                                    if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_RNT_PRICE)) {
                                        actTotalRnt = DecimalUtils.add(actTotalRnt, arAmt);
                                    }
                                    if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_PRINT_PRICE)) {
                                        actTotalPrint = DecimalUtils.add(actTotalPrint, arAmt);
                                    }
                                    if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_INT_PRICE)) {
                                        actTotalInt = DecimalUtils.add(actTotalInt, arAmt);
                                    }
                                }
                                if (prjPrdPaySchDVO.getPayPd().doubleValue() <= 6 && prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_INT_PRICE)) {
                                    if (prjPrdPaySchDVO.getPayPd().doubleValue() >= payPdFlow) {
                                        tmpInt = DecimalUtils.add(tmpInt, arAmt);
                                    }
                                }
                            }
                            for (PrjPrdPrpsFeeDetailVO payDetail : pay.getPrjPrdPayDetailList()) {
                                if (payDetail.getPayPd().intValue() < Integer.valueOf(payPdFlow).intValue()) {
                                    totalRnt = DecimalUtils.add(totalRnt, payDetail.getRntAmt());
                                    totalPrint = DecimalUtils.add(totalPrint, payDetail.getPrinAmt());
                                    totalInt = DecimalUtils.add(totalInt, payDetail.getIntAmt());
                                    feeList.add(payDetail);
                                }
                                if (null != stlMVO) {
                                    if (payDetail.getPayPd().intValue() == Integer.valueOf(payPdFlow).intValue()) {
                                        payDetail.setRntAmt(stlMVO.getRmS01ArTotAmt());
                                        payDetail.setPrinAmt(stlMVO.getRmS03ArTotAmt());
                                        payDetail.setIntAmt(stlMVO.getRmS02ArTotAmt());
                                        payDetail.setRemPrinAmt(0d);
                                        payDetail.setIsDel(PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                                        feeList.add(payDetail);
                                    }
                                } else {
                                    if (payDetail.getPayPd().intValue() == Integer.valueOf(payPdFlow).intValue()) {
                                        //提前还款剩余的期次为支付表实际剩余的租金、本金、利息
                                        payDetail.setRntAmt(actTotalPrint + tmpInt);
                                        payDetail.setPrinAmt(actTotalPrint);
                                        payDetail.setIntAmt(tmpInt);
                                        payDetail.setRemPrinAmt(0d);
                                        payDetail.setIsDel(PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                                        feeList.add(payDetail);
                                    }
                                }
                            }
                        } else {
                            feeList = pay.getPrjPrdPayDetailList();
                        }
                    } else {
                        feeList = pay.getPrjPrdPayDetailList();
                    }
                    listPage = new ListPageVO<PrjPrdPrpsFeeDetailVO>(feeList, feeList.size());
                    pay.setPrjQuatPrpsPaySchPage(listPage);
                }
                if (CollectionUtils.isNotEmpty(pay.getFeeDetailList())) {
                    List<PrjPrdPaySchDVO> list = new ArrayList<PrjPrdPaySchDVO>();
                    for (PrjPrdPaySchDVO prjPrdPaySchDVO : pay.getFeeDetailList()) {
                        if (prjPrdPaySchDVO.getFeeClsCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_PRPS) && !(prjPrdPaySchDVO.getCntWayCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_CONT))) {
                            list.add(prjPrdPaySchDVO);
                        }
                    }
                    //首期款合计项
                    PrjPrdPaySchDVO tatal = new PrjPrdPaySchDVO();
                    tatal.setFeeTypCdNm("首期款合计");
                    tatal.setFeeAmt(pay.getFirstPayAmt());
                    tatal.setPaidUpAmt(pay.getTotalFirstPayAmt().longValue());
                    list.add(tatal);
                    feeListPage = new ListPageVO<PrjPrdPaySchDVO>(list, list.size());
                    pay.setFeeDetailListPage(feeListPage);
                }
                if (CollectionUtils.isNotEmpty(pay.getSubFeeAmtTotalList())) {
                    for (PrjPrdPaySchDVO paySchDVO : pay.getSubFeeAmtTotalList()) {
                        paySchDVO.setFeeAmt(DecimalUtils.convertFenToYuan(paySchDVO.getFeeAmt().longValue()));
                    }
                }
            }
            List<SysDictionaryVO> settFeeTypCdListJSON = this.prjPrdPaySchMService.getSettFeeTypList();

            view.addObject("pay", pay);
            //view.addObject("cst", cst);
            view.addObject("prj", prj);
            view.addObject("dtl", dtl);
            view.addObject("showBk_oCIn", showBk_oCIn);
            view.addObject("isDetail_bk", isDetail_bk);
            view.addObject("showBk_oCOut", showBk_oCOut);
            view.addObject("editInto", editInto);
            view.addObject("editOut", editOut);
            view.addObject("subFeeAmtTotalList", JSON.toJSONString(pay.getSubFeeAmtTotalList()));
            view.addObject("listPage", JSON.toJSONString(listPage));
            view.addObject("feeListPage", JSON.toJSONString(feeListPage));
            view.addObject("paySchId", paySchId);
            view.addObject("settFeeTypCdListJSON", JSON.toJSONString(settFeeTypCdListJSON));
            view.addObject("optba", openTheBillAdd);
            view.addObject("optbf", openTheBillForFinance);
            view.addObject("optbd", openTheBillForDetail);
            view.addObject("procInstId", procInstId);
            view.addObject("confirm", confirm);
            view.addObject("fileAuth", request.getParameter("fileAuth"));
        } catch (BaseException ex) {
            BaseLogUtils.newLogger("结清流程中页面查询失败.").setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
            throw ex;
        } catch (Exception ex) {
            BaseLogUtils.newLogger("结清流程中页面查询失败.").setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
            throw ex;
        }
        return view;
    }

    /**
     * 起租通知书
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/exportRentNotice.do", method = {RequestMethod.GET})
    @ResponseBody
    public void exportRentNotice(HttpServletRequest request, HttpServletResponse response) {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
        String id = request.getParameter("id");//支付表ID
        try {
            if (StringUtils.isNotBlank(id)) {
                Document document = new Document();
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                String pdfName = "起租通知书";
                String strFileName = pdfName + ".pdf";
                response.setContentType("application/pdf");
                response.setCharacterEncoding("UTF-8");
                response.setHeader("Pragma", "public");
                response.setHeader("Cache-Control",
                        "must-revalidate, post-check=0, pre-check=0");
                response.setDateHeader("Expires", 0);
                if (request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") > 0) {
                    strFileName = URLEncoder.encode(strFileName, "UTF-8");
                } else {
                    strFileName = new String(strFileName.getBytes("UTF-8"), "ISO8859-1");
                }
                response.setHeader("Content-Disposition",
                        "attachment; filename=" + strFileName);
                ServletOutputStream o = response.getOutputStream();
                this.prjPrdPaySchMService.exportRentNotice(Long.valueOf(id), out);
                out.writeTo(o);
                o.flush();
                o.close();
            }
            BaseLogUtils.info(logger, "exportRentNotice", "导出起租通知书数据.[paySchId=" + id + "]", CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "exportRentNotice", "导出起租通知书数据失败.[paySchId=" + id + "]" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "exportRentNotice", "导出起租通知书据失败.[paySchId=" + id + "]" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        result.setSuccess(BaseConstant.IS_YESNO_YES);
    }


    /**
     * 支付表首期款明细表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/exportFirstPayAmt.do", method = {RequestMethod.GET})
    @ResponseBody
    public void exportFirstPayAmt(HttpServletRequest request, HttpServletResponse response) {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
        String id = request.getParameter("id");//支付表ID
        try {
            if (StringUtils.isNotBlank(id)) {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                String pdfName = "支付表首期款明细表";
                String strFileName = pdfName + ".pdf";
                response.setContentType("application/pdf");
                response.setCharacterEncoding("UTF-8");
                response.setHeader("Pragma", "public");
                response.setHeader("Cache-Control",
                        "must-revalidate, post-check=0, pre-check=0");
                response.setDateHeader("Expires", 0);
                if (request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") > 0) {
                    strFileName = URLEncoder.encode(strFileName, "UTF-8");
                } else {
                    strFileName = new String(strFileName.getBytes("UTF-8"), "ISO8859-1");
                }
                response.setHeader("Content-Disposition",
                        "attachment; filename=" + strFileName);
                ServletOutputStream o = response.getOutputStream();
                this.prjPrdPaySchMService.exportFirstPayAmt(Long.valueOf(id), out);
                out.writeTo(o);
                o.flush();
                o.close();
            }
            BaseLogUtils.info(logger, "exportFirstPayAmt", "导出支付表首期款明细表数据.[paySchId=" + id + "]", CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "exportFirstPayAmt", "导出支付表首期款明细表失败.[paySchId=" + id + "]" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "exportFirstPayAmt", "导出支付表首期款明细表失败.[paySchId=" + id + "]" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        result.setSuccess(BaseConstant.IS_YESNO_YES);
    }


    /**
     * 导出支付表信息
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/exportPrjPrdPaySch.do", method = {RequestMethod.GET})
    @ResponseBody
    public void exportPrjPrdPaySch(HttpServletRequest request, HttpServletResponse response) {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
        String id = request.getParameter("id");//支付表ID
        try {
            if (StringUtils.isNotBlank(id)) {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                String pdfName = "支付表";
                String strFileName = pdfName + ".xls";
                response.setContentType("application/msexcel");
                response.setCharacterEncoding("UTF-8");
                response.setHeader("Pragma", "public");
                response.setHeader("Cache-Control",
                        "must-revalidate, post-check=0, pre-check=0");
                response.setDateHeader("Expires", 0);
                if (request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") > 0) {
                    strFileName = URLEncoder.encode(strFileName, "UTF-8");
                } else {
                    strFileName = new String(strFileName.getBytes("UTF-8"), "ISO8859-1");
                }
                response.setHeader("Content-Disposition",
                        "attachment; filename=" + strFileName);
                ServletOutputStream o = response.getOutputStream();
                //  this.prjPrdPaySchMService.exportPrjPrdPaySch(Long.valueOf(id),out);
                this.prjPrdPaySchMService.exportPrjPrdPaySchExcelData(Long.valueOf(id), out);
                out.writeTo(o);
                o.flush();
                o.close();
            }
            BaseLogUtils.info(logger, "exportPrjPrdPaySch", "导出支付表数据.[paySchId=" + id + "]", CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "exportPrjPrdPaySch", "导出支付表失败.[paySchId=" + id + "]" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "exportPrjPrdPaySch", "导出支付表失败.[paySchId=" + id + "]" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        result.setSuccess(BaseConstant.IS_YESNO_YES);
    }


    /**
     * 到新增页面
     */
    @RequestMapping(value = "/toAddPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toAddPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toAddPage", "加载PrjPrdPaySchM Add页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView mav = new ModelAndView("project/prjprdquatprps/prjPrdQuatPrpsAdd");
        String prjPrdDtlId = request.getParameter("prjPrdDtlId");//项目商品明细ID
        String prjId = request.getParameter("prjId");//项目ID
        String prjPrdId = request.getParameter("prjPrdId");
        String id = request.getParameter("id");
        String detailFlag = request.getParameter("detailFlag");
        //资管支付表查看详情
        String zfDetailFlag = request.getParameter("zfDetailFlag");
        mav.addObject("zfDetailFlag", zfDetailFlag);

        Long sid = null;
        PrjPrdPaySchTMQC qc = new PrjPrdPaySchTMQC();
        qc.setPrjId(Long.valueOf(prjId));
        List<PrjPrdPaySchTMVO> prjPrdPaySchTMVOs = this.prjPrdPaySchTMService.searchList(qc);
        if (CollectionUtils.isNotEmpty(prjPrdPaySchTMVOs)) {
            sid = prjPrdPaySchTMVOs.get(0).getId();
            mav.addObject("isClx", 1);
        }
        mav.addObject("sid", sid);
        Long cumtomerPayId = null;
        PrjPrdPaySchMQueryCondition qc1 = new PrjPrdPaySchMQueryCondition();
        qc1.setPrjId(Long.valueOf(prjId));
        qc1.setIsSqBiz(BaseConstant.IS_YESNO_NO);
        qc1.setPaySchTypCd(PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_ZF);
        List<PrjPrdPaySchMVO> cumtomerPayList = this.prjPrdPaySchMService.searchList(qc1);
        if (CollectionUtils.isNotEmpty(cumtomerPayList)) {
            cumtomerPayId = cumtomerPayList.get(0).getId();
            mav.addObject("isCumtomerPay", 1);
        }
        mav.addObject("cumtomerPayId", cumtomerPayId);
        //费用类型
        JSONArray feeTypCdListJSON = this.prjQuatPrpsCfgMService.searchFeeTypCdList();
        mav.addObject("feeTypCdListJSON", feeTypCdListJSON);
        //费用计算基数
        List<KeyValueVO> calBaseCdList = this.prjQuatPrpsCfgMService.searchCalBaseCdList();
        if (CollectionUtils.isNotEmpty(calBaseCdList)) {
            for (int i = 0; i < calBaseCdList.size(); i++) {
                if (calBaseCdList.get(i).getKey().equals(PrjQuatPrpsConstant.CODE_CAL_BASE_CONTRACT)) {
                    calBaseCdList.remove(i);
                }
            }
        }
        mav.addObject("calBaseCdListJSON", JSON.toJSONString(calBaseCdList));
        List<KeyValueVO> yesNoCdList = this.prjQuatPrpsCfgMService.searchYesOrNoCdList();
        mav.addObject("yesOrNoCdListJSON", JSON.toJSONString(yesNoCdList));
        //费用计入方式
        List<KeyValueVO> cntWayCdList = this.prjQuatPrpsCfgMService.searchCntWayCdList();
        Map<String, String> scaleNumMap = this.prjQuatPrpsService.getDecimalDigitsByBuOrgCode();
        if (CollectionUtils.isNotEmpty(cntWayCdList)) {
            for (int i = 0; i < cntWayCdList.size(); i++) {
                if (cntWayCdList.get(i).getKey().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_FINANC)) {
                    cntWayCdList.remove(i);
                }
            }
        }
        PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(Long.valueOf(prjId));
        //REQ-4783【工行试单】工行试单业务系统支持 取消工行支付表不能修改限制
//        if (StringUtils.isNotBlank(prjBscInfoVO.getInsCode()) && prjBscInfoVO.getInsCode().equals(PrjBscInfoConstant.PRJ_INS_CODE_ICBC)) {
//            detailFlag = "true";
//        }
        if(prjBscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_ZK) &&prjBscInfoVO.getIsSplMfr().intValue()==BaseConstant.IS_YESNO_YES){
            PrjMfrPrdPaySchMQC schMQC = new PrjMfrPrdPaySchMQC();
            schMQC.setPrjPrdDtlId(Long.valueOf(prjPrdDtlId));
            List<PrjMfrPrdPaySchMVO> mfrList =  this.prjMfrPrdPaySchMService.searchList(schMQC);
            Long mfrId = null;
            if(CollectionUtils.isNotEmpty(mfrList)){
                mfrId = mfrList.get(0).getId();
                mav.addObject("mfrId", mfrId);
            }
        }
        Integer isCalFlag = BaseConstant.IS_YESNO_YES;
        if (prjBscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_XNY) || StringUtils.isNotBlank(prjBscInfoVO.getInsCode())) {
            isCalFlag = BaseConstant.IS_YESNO_NO;
        }
        mav.addObject("isCalFlag", isCalFlag);
        //计算方式
        mav.addObject("cntWayCdListJSON", JSON.toJSONString(cntWayCdList));
        mav.addObject("prjId", prjId);
        mav.addObject("prjPrdDtlId", prjPrdDtlId);
        mav.addObject("prjPrdId", prjPrdId);
        mav.addObject("id", id);
        mav.addObject("detailFlag", detailFlag);
        mav.addObject("insCode", null == prjBscInfoVO.getInsCode() ? "" : prjBscInfoVO.getInsCode());
        mav.addObject("scaleNumMap", scaleNumMap.isEmpty() == true ? "" : JSON.toJSONString(scaleNumMap));

        //项目类型
        mav.addObject("prjTypCd", null == prjBscInfoVO.getPrjTypCd() ? "" : prjBscInfoVO.getPrjTypCd());
        if (PrjBscInfoConstant.COMPENSATORY_TYPE_2.equals(prjBscInfoVO.getCompensatoryType())){
            // 报价方案
            mav.addObject("compensatoryType",prjBscInfoVO.getCompensatoryType()==null?"0":prjBscInfoVO.getCompensatoryType());
            // 渠道保证金处理方式
            List<KeyValueVO> chlDpstPwayCdList = sysDictionaryApiService.getKvList(DictionaryConstant.CHL_DPST_PWAY_GRP_CD, CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());
            mav.addObject("chlDpstPwayCdList", chlDpstPwayCdList);
            PrjQuatPrpsQueryCondition con = new PrjQuatPrpsQueryCondition() ;
            con.setPrjId(Long.valueOf(prjId));
            con.setPrpsTypCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_TYP_OFFICIAL);
            List<PrjQuatPrpsVO> prjQuatPrpsVOS = prjQuatPrpsService.searchList(con);
            String chlDpstPwayCd = prjQuatPrpsVOS.get(0).getChlDpstPwayCd();
            Integer rtnPdStart = prjQuatPrpsVOS.get(0).getRtnPdStart();
            Integer rtnPdEnd = prjQuatPrpsVOS.get(0).getRtnPdEnd();
            // 保证金担保业务字段
            mav.addObject("chlDpstPwayCd",chlDpstPwayCd);
            mav.addObject("rtnPdStart",rtnPdStart);
            mav.addObject("rtnPdEnd",rtnPdEnd);
        }
        //事业部
        mav.addObject("buOrgCd",prjBscInfoVO.getBuOrgCd());
        //加上平安信托标示 为了去掉支付表详情按纽
        try {
            String pian = request.getParameter("pian");
            mav.addObject("pian", pian);
            if(StringUtils.isNotEmpty(pian) && "101".equals(pian)){
                String fncPrjId = request.getParameter("fncPrjId"); //再融资项目ID
                if(StringUtils.isNotEmpty(fncPrjId)){
                    FncPrjBscInfoVO fncPrjBscInfoVO = this.fncPrjBscInfoService.selectById(Long.valueOf(fncPrjId));
                    if(null != fncPrjBscInfoVO){
                        mav.addObject("isDisAge", fncPrjBscInfoVO.getIsDisAge());
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return mav;
    }


    /**
     * 到新增页面(资管支付表)
     */
    @RequestMapping(value = "/toZfAddPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toZfAddPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toAddPage", "加载PrjPrdPaySchM Add页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView mav = new ModelAndView("project/prjprdquatprps/prjPrdQuatPrpsAdd");
        String prjPrdDtlId = request.getParameter("prjPrdDtlId");//项目商品明细ID
        String prjId = request.getParameter("prjId");//项目ID
        String prjPrdId = request.getParameter("prjPrdId");
        String id = request.getParameter("id");
        String detailFlag = request.getParameter("detailFlag");
        String zfDetailFlag = "true";
        Long sid = null;
        /*
        PrjPrdPaySchTMQC qc = new PrjPrdPaySchTMQC();
        qc.setPrjId(Long.valueOf(prjId));
        List<PrjPrdPaySchTMVO> prjPrdPaySchTMVOs = this.prjPrdPaySchTMService.searchList(qc);
        if (CollectionUtils.isNotEmpty(prjPrdPaySchTMVOs)) {
            sid = prjPrdPaySchTMVOs.get(0).getId();
            mav.addObject("isClx", 1);
        }
        */
        mav.addObject("sid", sid);
        /*
        Long cumtomerPayId = null;
        PrjPrdPaySchMQueryCondition qc1 = new PrjPrdPaySchMQueryCondition();
        qc1.setPrjId(Long.valueOf(prjId));
        qc1.setIsSqBiz(BaseConstant.IS_YESNO_NO);
        qc1.setPaySchTypCd(PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_ZF);
        List<PrjPrdPaySchMVO> cumtomerPayList = this.prjPrdPaySchMService.searchList(qc1);
        if (CollectionUtils.isNotEmpty(cumtomerPayList)) {
            cumtomerPayId = cumtomerPayList.get(0).getId();
            mav.addObject("isCumtomerPay", 1);
        }
        mav.addObject("cumtomerPayId", cumtomerPayId);
        */
        //费用类型
        JSONArray feeTypCdListJSON = this.prjQuatPrpsCfgMService.searchFeeTypCdList();
        mav.addObject("feeTypCdListJSON", feeTypCdListJSON);
        //费用计算基数
        List<KeyValueVO> calBaseCdList = this.prjQuatPrpsCfgMService.searchCalBaseCdList();
        if (CollectionUtils.isNotEmpty(calBaseCdList)) {
            for (int i = 0; i < calBaseCdList.size(); i++) {
                if (calBaseCdList.get(i).getKey().equals(PrjQuatPrpsConstant.CODE_CAL_BASE_CONTRACT)) {
                    calBaseCdList.remove(i);
                }
            }
        }
        mav.addObject("calBaseCdListJSON", JSON.toJSONString(calBaseCdList));
        List<KeyValueVO> yesNoCdList = this.prjQuatPrpsCfgMService.searchYesOrNoCdList();
        mav.addObject("yesOrNoCdListJSON", JSON.toJSONString(yesNoCdList));
        //费用计入方式
        List<KeyValueVO> cntWayCdList = this.prjQuatPrpsCfgMService.searchCntWayCdList();
        Map<String, String> scaleNumMap = this.prjQuatPrpsService.getDecimalDigitsByBuOrgCode();
        if (CollectionUtils.isNotEmpty(cntWayCdList)) {
            for (int i = 0; i < cntWayCdList.size(); i++) {
                if (cntWayCdList.get(i).getKey().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_FINANC)) {
                    cntWayCdList.remove(i);
                }
            }
        }
        PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(Long.valueOf(prjId));
        //REQ-4783【工行试单】工行试单业务系统支持 取消工行支付表不能修改限制
//        if (StringUtils.isNotBlank(prjBscInfoVO.getInsCode()) && prjBscInfoVO.getInsCode().equals(PrjBscInfoConstant.PRJ_INS_CODE_ICBC)) {
//            detailFlag = "true";
//        }

        if(prjBscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_ZK)&&prjBscInfoVO.getIsSplMfr().intValue()==BaseConstant.IS_YESNO_YES){
            PrjMfrPrdPaySchMQC schMQC = new PrjMfrPrdPaySchMQC();
            schMQC.setPrjPrdDtlId(Long.valueOf(prjPrdDtlId));
            List<PrjMfrPrdPaySchMVO> mfrList =  this.prjMfrPrdPaySchMService.searchList(schMQC);
            Long mfrId = null;
            if(CollectionUtils.isNotEmpty(mfrList)){
                mfrId = mfrList.get(0).getId();
                mav.addObject("mfrId", mfrId);
            }
        }
        Integer isCalFlag = BaseConstant.IS_YESNO_YES;
        if (prjBscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_XNY) || StringUtils.isNotBlank(prjBscInfoVO.getInsCode())) {
            isCalFlag = BaseConstant.IS_YESNO_NO;
        }
        mav.addObject("isCalFlag", isCalFlag);
        //计算方式
        mav.addObject("cntWayCdListJSON", JSON.toJSONString(cntWayCdList));
        mav.addObject("prjId", prjId);
        mav.addObject("prjPrdDtlId", prjPrdDtlId);
        mav.addObject("prjPrdId", prjPrdId);
        mav.addObject("id", id);
        mav.addObject("detailFlag", detailFlag);
        mav.addObject("zfDetailFlag", zfDetailFlag);
        mav.addObject("insCode", null == prjBscInfoVO.getInsCode() ? "" : prjBscInfoVO.getInsCode());
        mav.addObject("scaleNumMap", scaleNumMap.isEmpty() == true ? "" : JSON.toJSONString(scaleNumMap));
        //加上平安信托标示 为了去掉支付表详情按纽
        try {
            String pian = request.getParameter("pian");
            mav.addObject("pian", pian);
            if(StringUtils.isNotEmpty(pian) && "101".equals(pian)){
                String fncPrjId = request.getParameter("fncPrjId"); //再融资项目ID
                if(StringUtils.isNotEmpty(fncPrjId)){
                    FncPrjBscInfoVO fncPrjBscInfoVO = this.fncPrjBscInfoService.selectById(Long.valueOf(fncPrjId));
                    if(null != fncPrjBscInfoVO){
                        mav.addObject("isDisAge", fncPrjBscInfoVO.getIsDisAge());
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return mav;
    }

    /**
     * 到详情页面
     */
    @RequestMapping(value = "/toDetailPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toDetailPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toDetailPage", "加载PrjPrdPaySchM Add页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView mav = new ModelAndView("project/prjprdquatprps/prjPrdQuatPrpsAdd");
        String id = request.getParameter("id");
        Long sid = null;
        Long cumtomerPayId = null;

        mav.addObject("cumtomerPayId", cumtomerPayId);
        mav.addObject("sid", sid);
        //费用类型
        JSONArray feeTypCdListJSON = this.prjQuatPrpsCfgMService.searchFeeTypCdList();
        mav.addObject("feeTypCdListJSON", feeTypCdListJSON);
        //费用计算基数
        List<KeyValueVO> calBaseCdList = this.prjQuatPrpsCfgMService.searchCalBaseCdList();
        if (CollectionUtils.isNotEmpty(calBaseCdList)) {
            for (int i = 0; i < calBaseCdList.size(); i++) {
                if (calBaseCdList.get(i).getKey().equals(PrjQuatPrpsConstant.CODE_CAL_BASE_CONTRACT)) {
                    calBaseCdList.remove(i);
                }
            }
        }
        mav.addObject("calBaseCdListJSON", JSON.toJSONString(calBaseCdList));
        List<KeyValueVO> yesNoCdList = this.prjQuatPrpsCfgMService.searchYesOrNoCdList();
        mav.addObject("yesOrNoCdListJSON", JSON.toJSONString(yesNoCdList));
        //费用计入方式
        List<KeyValueVO> cntWayCdList = this.prjQuatPrpsCfgMService.searchCntWayCdList();
        Map<String, String> scaleNumMap = this.prjQuatPrpsService.getDecimalDigitsByBuOrgCode();
        if (CollectionUtils.isNotEmpty(cntWayCdList)) {
            for (int i = 0; i < cntWayCdList.size(); i++) {
                if (cntWayCdList.get(i).getKey().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_FINANC)) {
                    cntWayCdList.remove(i);
                }
            }
        }
        PrjPrdPaySchMVO schMVO = this.prjPrdPaySchMService.selectById(Long.valueOf(id));
        PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(schMVO.getPrjId());
        PrjPrdDtlVO dtlVO = null;
        if (StringUtils.isBlank(prjBscInfoVO.getInsCode()) || PrjBscInfoConstant.PRJ_INS_CODE_SQ.equals(prjBscInfoVO.getInsCode())) {
            //非资管项目
            PrjPrdDtlQueryCondition prjPrdDtlQc = new PrjPrdDtlQueryCondition();
            prjPrdDtlQc.setPaySchId(Long.valueOf(id));
            List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(prjPrdDtlQc);
            if (CollectionUtils.isNotEmpty(dtlList)) {
                dtlVO = dtlList.get(0);
            }
        } else {
            //资管项目
            PrjPrdDtlQueryCondition qc = new PrjPrdDtlQueryCondition();
            qc.setPrjId(schMVO.getPrjId());
            List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(qc);
            if (CollectionUtils.isNotEmpty(dtlList)) {
                dtlVO = dtlList.get(0);
            }
        }

        Integer isCalFlag = BaseConstant.IS_YESNO_YES;
        mav.addObject("isCalFlag", isCalFlag);
        //计算方式
        mav.addObject("cntWayCdListJSON", JSON.toJSONString(cntWayCdList));
        mav.addObject("prjId", schMVO.getPrjId());
        mav.addObject("prjPrdDtlId", dtlVO.getId());
        mav.addObject("prjPrdId", dtlVO.getPrjPrdId());
        mav.addObject("id", id);
        mav.addObject("detailFlag", "true");
        mav.addObject("buOrgCd", prjBscInfoVO.getBuOrgCd());
        mav.addObject("insCode", null == prjBscInfoVO.getInsCode() || PrjBscInfoConstant.PRJ_INS_CODE_SQ.equals(prjBscInfoVO.getInsCode()) ? "" : prjBscInfoVO.getInsCode());
        mav.addObject("scaleNumMap", scaleNumMap.isEmpty() == true ? "" : JSON.toJSONString(scaleNumMap));
        return mav;
    }

    /**
     * 到修改页面
     */
    @RequestMapping(value = "/toModifyPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toModifyPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toModifyPage", "加载PrjPrdPaySchM Modify页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView mav = new ModelAndView("project/prjPrdPaySchM/prjPrdPaySchMModify");
        this.prepare(request, mav);

        String id = request.getParameter("id");
        PrjPrdPaySchMVO prjPrdPaySchMVO = this.prjPrdPaySchMService.selectById(Long.valueOf(id));
        mav.addObject("prjPrdPaySchMVO", prjPrdPaySchMVO);
        return mav;
    }

    /**
     * 到详细页面
     */
    @RequestMapping(value = "/toPrjPrdPaySchMDetailPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toPrjPrdPaySchMDetailPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toPrjPrdPaySchMDetailPage", "加载toPrjPrdPaySchMDetailPage Modify页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView mav = new ModelAndView("project/prjprdquatprps/prjPrdPaySchMDetailPage");
        String id = request.getParameter("id");
        //资管支付表标志
        String zfFlag = request.getParameter("zfFlag");
        PrjPrdPaySchMVO vo = null;
        CapOverdueInfoVO cap = null;
        double totalPardUpAmt = 0d;
        double totalRntAmt = 0d;
        List<PrjPrdPaySchDVO> payList = new ArrayList<PrjPrdPaySchDVO>();
        ListPageVO<PrjPrdPaySchDVO> listPage = null;
        if (StringUtils.isNotBlank(id)) {
            if ("true".equals(zfFlag)) {
                //资管支付表详情页面
                vo = this.prjPrdPaySchMService.selectPrjPrdPaySchMEnableAndDetailById(Long.valueOf(id));
                mav.addObject("zfFlag",zfFlag);
            }else {
                vo = this.prjPrdPaySchMService.selectPrjPrdPaySchMAndDetailById(Long.valueOf(id));
            }
            if ("SH".equals(vo.getPaySchTypCd())) {
                mav.addObject("shFlag","SH");
            }
            Long sid = null;
            PrjPrdPaySchTMQC qc = new PrjPrdPaySchTMQC();
            qc.setPrjId(vo.getPrjId());
            List<PrjPrdPaySchTMVO> prjPrdPaySchTMVOs = this.prjPrdPaySchTMService.searchList(qc);
            if (CollectionUtils.isNotEmpty(prjPrdPaySchTMVOs)) {
                sid = prjPrdPaySchTMVOs.get(0).getId();
                mav.addObject("isClx", 1);
            }
            Long cumtomerPayId = null;
            PrjPrdPaySchMQueryCondition qc1 = new PrjPrdPaySchMQueryCondition();
            qc1.setPrjId(vo.getPrjId());
            qc1.setIsSqBiz(BaseConstant.IS_YESNO_NO);
            List<PrjPrdPaySchMVO> cumtomerPayList = this.prjPrdPaySchMService.searchList(qc1);
            if (CollectionUtils.isNotEmpty(cumtomerPayList)) {
                cumtomerPayId = cumtomerPayList.get(0).getId();
                mav.addObject("isCumtomerPay", 1);
            }
            mav.addObject("cumtomerPayId", cumtomerPayId);
            mav.addObject("sid", sid);

            CapOverdueInfoQueryCondition capQc = new CapOverdueInfoQueryCondition();
            capQc.setIsDel(BaseConstant.IS_YESNO_NO);
            capQc.setPaySchId(Long.valueOf(id));
            capQc.setOverdueStatusCd(BaseConstant.IS_YESNO_NO + "");
            capQc.setCreateDate(new Date());
            List<CapOverdueInfoVO> capList = capOverdueInfoService.searchOvdDtlList(capQc);
            if (CollectionUtils.isNotEmpty(vo.getPrjPrdPaySchDList())) {
                List<PrjPrdPaySchDVO> list = vo.getPrjPrdPaySchDList();
                List<PrjPrdPaySchDVO> totalList = new ArrayList<PrjPrdPaySchDVO>();
                for (PrjPrdPaySchDVO detail : vo.getFeeDetailList()) {
                    if (detail.getCntWayCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_DOWNPAY)) {
                        totalList.add(detail);
                    }
                    if (null != detail.getFeeTypCd() && (detail.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.CODE_FEE_WAY_TYPE_RICK_DEP) || detail.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_104))) {
                        totalList.add(detail);
                    }
                }
                totalList.addAll(list);
                for (PrjPrdPaySchDVO prjPrdPaySchDVO : totalList) {
                    //转换分为元
                    if (null == prjPrdPaySchDVO.getCntWayCd()) {
                        if (null != prjPrdPaySchDVO.getFeeAmt()) {
                            prjPrdPaySchDVO.setFeeAmt(DecimalUtils.convertFenToYuan(prjPrdPaySchDVO.getFeeAmt().longValue()));
                        }
                    }
                    if (prjPrdPaySchDVO.getPayPd() == PrjQuatPrpsConstant.CODE_PRJ_PRD_FEE_PD.intValue() || prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_RNT_PRICE)) {
                        payList.add(prjPrdPaySchDVO);
                        //计算合计信息
                        double paidUpAmt = DecimalUtils.convertFenToYuan(prjPrdPaySchDVO.getPaidUpAmt());
                        totalPardUpAmt = DecimalUtils.add(totalPardUpAmt, paidUpAmt == 0d ? 0 : paidUpAmt);
                    }
                }
                totalRntAmt = DecimalUtils.add(vo.getTotalRntAmt(), vo.getFirstPayAmt());
            }

            listPage = new ListPageVO<PrjPrdPaySchDVO>(payList, payList.size());
            if (CollectionUtils.isNotEmpty(capList)) {
                capList.get(0);
            }
        }
        mav.addObject("listPage", JSON.toJSONString(listPage));
        mav.addObject("cap", cap);
        mav.addObject("totalPardUpAmt", totalPardUpAmt);
        mav.addObject("totalRntAmt", totalRntAmt);
        if(CollectionUtils.isNotEmpty(payList) && null != payList.get(0) && null != payList.get(0).getPaySchId()){
            BaseLogUtils.info(logger, "toPrjPrdPaySchMDetailPage", "返回支付表id oId="+id+",nId="+payList.get(0).getPaySchId().toString()+".", CurrentThreadContext.getCurrentUserName());
        	id = payList.get(0).getPaySchId().toString();
        }
        mav.addObject("id", id);
        //REQ-7326  加上外部机构标示 为了屏蔽部分信息 by gengchunlan
        try {
            String rfbase = request.getParameter("rfbase");
            mav.addObject("rfbase", rfbase);
        } catch (Exception e) {
            e.printStackTrace();
        }//end by gengchunlan
        return mav;
    }

    /**
     * 到划扣记录页面
     */
    @RequestMapping(value = "/toWithholdRecordPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toWithholdRecordPage(HttpServletRequest request, HttpServletResponse response) {
        String prjId = request.getParameter("prjId");
        PrjBscInfoVO prjBscInfoVO = prjBscInfoService.selectById(Long.valueOf(prjId));
        BaseLogUtils.info(logger, "toWithholdRecordPage", "toWithholdRecordPage页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView mav = new ModelAndView("project/prjprdquatprps/prjWithholdRecordPage");
        mav.addObject("cstNm",prjBscInfoVO.getCstNm());
        mav.addObject("lsCntNo",prjBscInfoVO.getLsCntNo());
        mav.addObject("prjId",prjId);
        return mav;
    }

    /**
     * 查询划扣记录列表
     */
    @RequestMapping(value = "/getWithholdRecord.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object getWithholdRecord(HttpServletRequest request, HttpServletResponse response) {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
        String prjId = request.getParameter("prjId");
        QueryWithholdRecordRequest queryWithholdRecordRequest = new QueryWithholdRecordRequest();
        queryWithholdRecordRequest.setBeginNumber(0);
        queryWithholdRecordRequest.setBizSN(prjId);
        queryWithholdRecordRequest.setInsCode("ylbank");
        queryWithholdRecordRequest.setPageSize(3);
        BaseLogUtils.newLogger("查询划扣记录列表接口Begin：prjId={}, request={}", prjId, JSON.toJSONString(queryWithholdRecordRequest)).info();
        ResponseData responseData = this.financialService.qyeryWithholdRecord(queryWithholdRecordRequest);
        BaseLogUtils.newLogger("查询划扣记录列表接口End:prjId={}, response={}", prjId, JSON.toJSONString(responseData)).info();
        List<DeductLogVO> deductLogVOs = new ArrayList<DeductLogVO>();
        if (PreloanResultCodeEnum.SUCCESS.getCode().equals(responseData.getCode())) {
            QueryWithholdRecordResultDTO queryWithholdRecordResultDTO = (QueryWithholdRecordResultDTO)responseData.getData();
            List<DeductLog> deductLogs = queryWithholdRecordResultDTO.getDeductLogList();
            for (DeductLog deductLog : deductLogs) {
                DeductLogVO deductLogVO = new DeductLogVO();
                deductLogVO.setPayAmt(DecimalUtils.convertFenToYuan(deductLog.getPayAmt()));
                deductLogVO.setBankAccNo(deductLog.getBankAccNo());
                deductLogVO.setFailDesc(deductLog.getFailDesc());
                deductLogVO.setPayApplyDt(deductLog.getPayApplyDt());
                deductLogVO.setPayStsCd(deductLog.getPayStsCd());
                deductLogVO.setPayDt(deductLog.getPayDt());
                deductLogVOs.add(deductLogVO);
            }
        }
        ListPageVO<DeductLogVO> listPage = new ListPageVO<DeductLogVO>(deductLogVOs, deductLogVOs.size());
        return listPage;
    }

    /**
     * 到查看付款情况页面
     */
    @RequestMapping(value = "/toPrjPrdPaySchMAndDListPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toPrjPrdPaySchMAndDListPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toPrjPrdPaySchMAndDListPage", "加载toPrjPrdPaySchMAndDListPage页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView mav = new ModelAndView("project/prjprdquatprps/prjPrdPaySchMAndDListPage");
        ListPageVO<PrjPrdPaySchDVO> allListPage = null;
        List<PrjPrdPaySchDVO> listVO = new ArrayList<PrjPrdPaySchDVO>();
        String prjId = request.getParameter("prjId");
        PrjPrdPaySchMQueryCondition condition = new PrjPrdPaySchMQueryCondition();
        if (StringUtils.isNotEmpty(prjId)) {
            condition.setPrjId(Long.parseLong(prjId));
        }
        //查询启用支付表
        condition.setIsEnable(BaseConstant.IS_YESNO_YES);
        condition.setIsAllBiz(BaseConstant.IS_YESNO_YES);
        List<PrjPrdPaySchMVO> prjPrdPaySchMVOList = this.prjPrdPaySchMService.searchList(condition);
        if (CollectionUtils.isNotEmpty(prjPrdPaySchMVOList)) {
            for (PrjPrdPaySchMVO mVO : prjPrdPaySchMVOList) {
                PrjPrdPaySchMVO vo = null;
                if (StringUtils.isNotEmpty(mVO.getId())) {
                    vo = this.prjPrdPaySchMService.selectPrjPrdPaySchMAndDetailById(mVO.getId());
                    if (null != vo && CollectionUtils.isNotEmpty(vo.getPrjPrdPaySchDList())) {
                        for (PrjPrdPaySchDVO prjPrdPaySchDVO : vo.getPrjPrdPaySchDList()) {
                            if (null == prjPrdPaySchDVO.getCntWayCd()) {
                                if (null != prjPrdPaySchDVO.getFeeAmt()) {
                                    prjPrdPaySchDVO.setFeeAmt(DecimalUtils.convertFenToYuan(prjPrdPaySchDVO.getFeeAmt().longValue()));
                                }
                            }
                            if (prjPrdPaySchDVO.getPayPd() == PrjQuatPrpsConstant.CODE_PRJ_PRD_FEE_PD.intValue() || prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_RNT_PRICE)) {
                                listVO.add(prjPrdPaySchDVO);
                            }
                        }
                    }
                }
            }
        }

        if (CollectionUtils.isNotEmpty(listVO)) {
            allListPage = new ListPageVO<PrjPrdPaySchDVO>(listVO, listVO.size());
        }
        mav.addObject("listPage", JSON.toJSONString(allListPage));
        return mav;
    }


    /**
     * 加载数据字典数据、传值等
     *
     * @param request
     * @param mav
     */
    public void prepare(HttpServletRequest request, ModelAndView mav) {
        // 事业部
        List<KeyValueVO> orgList = this.cstBscInfoService.searchBusinessOrgList();
        mav.addObject("fundBelongOrgCdList", JSON.toJSONString(orgList));
    }

    /**
     * 测算
     */
    @RequestMapping(value = "/calculate.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object calculate(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
        PrjPrdPaySchMVO entity = null;//获取参数
        Long id = null;
        try {
            entity = this.getRequestParamForPrjPrdPaySchM(request);//获取参数
            //测算
            entity = this.prjPrdPaySchMService.prjQuatPrpsCalculate(entity);
            ListPageVO<PrjPrdPrpsFeeDetailVO> listPage = new ListPageVO<PrjPrdPrpsFeeDetailVO>(entity.getPrjPrdPayDetailList(), entity.getPrjPrdPayDetailList().size());
            entity.setPrjQuatPrpsPaySchPage(listPage);
            result.setData(entity);
            BaseLogUtils.info(logger, "calculate", "测算数据.[id=" + id + "] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "calculate", "测算数据失败.DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "calculate", "测算数据失败.DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }

        return result;
    }

    /**
     * 设置还款日，设置支付表具体的还款日期
     */
    @RequestMapping(value = "/firstPayDate.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object firstPayDate(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
        String prjId = request.getParameter("prjId");
        String prjPrdPayId = request.getParameter("prjPrdPayId");//支付表编号
        String firstPayDate = request.getParameter("firstPayDate");//还款日
        Long id = null;
        try {
            if (StringUtils.isEmpty(firstPayDate)) {
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "还款日期不能为空!");
            }
            if (StringUtils.isEmpty(prjPrdPayId)) {
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "请选择支付表!");
            }
            this.prjPrdPaySchMService.setPrjPrdSchMPayDate(Long.valueOf(prjPrdPayId), DateUtils.formatStringToDate(firstPayDate, DateUtils.YYYY_MM_DD));

            BaseLogUtils.info(logger, "setLeaseDate", "设置起租日.[id=" + id + "] DATA:" + JSONObject.toJSONString(firstPayDate), CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "calculate", "设置起租日失败.DATA:" + JSONObject.toJSONString(firstPayDate) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "calculate", "设置起租日失败.DATA:" + JSONObject.toJSONString(firstPayDate) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }

        return result;
    }

    /**
     * 初始化列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object initPrjPrdPaySchMList(HttpServletRequest request, HttpServletResponse response) {
        String currentPage = request.getParameter("page");
        String pageSize = request.getParameter("pagesize");
        Pager page = new Pager();
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setCurrentPage(Integer.parseInt(currentPage));
        }

        if (StringUtils.isNotEmpty(currentPage)) {
            page.setEveryPage(Integer.parseInt(pageSize));
        }

        PrjPrdPaySchMQueryCondition qc = new PrjPrdPaySchMQueryCondition();
        page.setCondition(qc);

        BaseLogUtils.info(logger, "initPrjPrdPaySchMList", "初始化PrjPrdPaySchM列表页面数据.DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
        Pager pager = this.prjPrdPaySchMService.searchListPage(page);
        List<PrjPrdPaySchMVO> list = (List<PrjPrdPaySchMVO>) pager.getResultList();
        ListPageVO<PrjPrdPaySchMVO> listPage = new ListPageVO<PrjPrdPaySchMVO>(list, pager.getTotalCount());
        return listPage;
    }

    /**
     * 支付表管理
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/getPrjPrdPaySchMList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object getPrjPrdPaySchMList(HttpServletRequest request, HttpServletResponse response) {
        String currentPage = request.getParameter("page");
        String pageSize = request.getParameter("pagesize");
        String prjNm = request.getParameter("prjNm");//项目名称
        String splNm = request.getParameter("splNm");//供应商名称
        String prjTypCd = request.getParameter("prjTypCd");//项目类型
        String buOrgCd = request.getParameter("buOrgCd");//事业部
        String bizTypCd = request.getParameter("bizTypCd");//业务模式
        String lsDt = request.getParameter("lsDt");//起租日期
        String cstNm = request.getParameter("cstNm");//客户名称
        String lsCntNo = request.getParameter("lsCntNo");//合同编号
        String timeType = request.getParameter("timeType");//时间类型
        String strDate = request.getParameter("strDate");//开始时间
        String endDate = request.getParameter("endDate");//结束时间
        String prdStsCd = request.getParameter("prdStsCd");//支付表状态
        String paySchNo = request.getParameter("paySchNo");//支付表号
        String isDel = request.getParameter("isDel");
        String transFlg = request.getParameter("transFlg");
        String bizFlag = request.getParameter("bizFlag");
        String tagTypeCd = request.getParameter("tagTypeCd");
        String icbcFlag = request.getParameter("icbcFlag");
        String isLowBiz = request.getParameter("isLowBiz");//是否低息
        // 一级支付表状态
        String firstPrdStsCd = request.getParameter("firstPrdStsCd");
        //支付表类型，初始化默认查询我司支付表流水 但工行卡贷只有资方支付表，若icbcFlag为1时，支付表类型不默认为我司
        String paySchTypCd = null;
        String insCode = null;
        if ("1".equals(icbcFlag)) {
            insCode = PrjBscInfoConstant.PRJ_INS_CODE_ICBC;
        } else {
            paySchTypCd = "WS";
        }

        Pager page = new Pager();
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setCurrentPage(Integer.parseInt(currentPage));
        }

        if (StringUtils.isNotEmpty(currentPage)) {
            page.setEveryPage(Integer.parseInt(pageSize));
        }
        PrjPrdPaySchMQueryCondition qc = new PrjPrdPaySchMQueryCondition();
        if (StringUtils.isNotEmpty(firstPrdStsCd)) {
            qc.setFirstPrdStsCd(firstPrdStsCd);
        }
        if (StringUtils.isNotBlank(prdStsCd)) {
            qc.setPrdStsCd(prdStsCd);
        }
        if (StringUtils.isNotBlank(isDel)) {
            qc.setIsDel(Integer.valueOf(isDel));
        }
        if (StringUtils.isNotBlank(paySchNo)) {
            qc.setPaySchNo(paySchNo);
        }
        if (StringUtils.isNotBlank(strDate)) {
            qc.setStrDt(DateUtils.formatStringToDate(strDate, DateUtils.YYYY_MM_DD));
        }
        if (StringUtils.isNotBlank(timeType)) {
            if (timeType.equals(PrjPrdPaySchDConstant.CODE_TIME_TYPE_STL)) {
                qc.setStlDt(qc.getStrDt() == null ? null : qc.getStrDt());
            }
            if (timeType.equals(PrjPrdPaySchDConstant.CODE_TIME_TYPE_BACK)) {
                qc.setBackDt(qc.getStrDt() == null ? null : qc.getStrDt());
            }
            if (timeType.equals(PrjPrdPaySchDConstant.CODE_TIME_TYPE_FORM)) {
                qc.setFormDt(qc.getStrDt() == null ? null : qc.getStrDt());
            }
        }
        if (StringUtils.isNotBlank(endDate)) {
            qc.setEndDt(DateUtils.formatStringToDate(endDate, DateUtils.YYYY_MM_DD));
        }
        if (StringUtils.isNotEmpty(cstNm)) {
            qc.setCstNm(cstNm);
        }
        if (StringUtils.isNotBlank(lsCntNo)) {
            qc.setLsCntNo(lsCntNo);
        }
        if (StringUtils.isNotEmpty(prjNm)) {
            qc.setPrjNm(prjNm);
        }
        if (StringUtils.isNotEmpty(splNm)) {
            qc.setSplNm(splNm);
        }
        if (StringUtils.isNotEmpty(prjTypCd)) {
            qc.setPrjTypCd(prjTypCd);
        }
        if (StringUtils.isNotEmpty(buOrgCd)) {
            qc.setBuOrgCd(buOrgCd);
        }
        if (StringUtils.isNotEmpty(bizTypCd)) {
            qc.setBizTypCd(bizTypCd);
        }
        if (StringUtils.isNotEmpty(transFlg)) {
            qc.setTransFlg(Long.valueOf(transFlg));
        }
        if (StringUtils.isNotEmpty(lsDt)) {
            qc.setLsDt(DateUtils.formatStringToDate(lsDt, DateUtils.YYYY_MM_DD));
        }
        if (StringUtils.isNotBlank(bizFlag)) {
            qc.setBizFlag(bizFlag);
        }
        if (StringUtils.isNotEmpty(tagTypeCd)) {
            qc.setTagTypeCd(tagTypeCd);
        }
        String prjId=request.getParameter("prjId");
        if (StringUtils.isNotBlank(prjId)) {
            qc.setPrjId(Long.valueOf(prjId));
        }
        if (StringUtils.isNotEmpty(paySchTypCd)) {
            qc.setPaySchTypCd(paySchTypCd);
        }
        //第三方机构
        if (StringUtils.isNotEmpty(insCode)) {
            qc.setInsCode(insCode);
        }
        if(StringUtils.isNotBlank(isLowBiz)){
            qc.setIsLowBiz(Integer.valueOf(isLowBiz));
        }
        qc.setUsrId(CurrentThreadContext.getCurrentUserId());
        qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
        qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
        page.setCondition(qc);
        BaseLogUtils.info(logger, "initPrjPrdPaySchMList", "初始化PrjPrdPaySchM列表页面数据.DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
        Pager pager = null;
        if (StringUtils.isNotBlank(isDel) && isDel.equals(BaseConstant.IS_YESNO_YES)) {
            BaseLogUtils.info(logger, "getPrjPrdPaySchMList", "AAAA:" + JSONObject.toJSONString(qc), CurrentThreadContext.getCurrentUserName());

            pager = this.prjPrdPaySchMService.selectPrjPrdPaySchMDelMgrListPage(page);
        } else {
            BaseLogUtils.info(logger, "getPrjPrdPaySchMList", "BBBB:" + JSONObject.toJSONString(qc), CurrentThreadContext.getCurrentUserName());
            pager = this.prjPrdPaySchMService.selectPrjPrdPaySchMMgrListPage(page);
        }
        List<PrjPrdPaySchMVO> list = (List<PrjPrdPaySchMVO>) pager.getResultList();
        BaseLogUtils.info(logger, "getPrjPrdPaySchMList", "支付表管理list:" + JSONObject.toJSONString(list), CurrentThreadContext.getCurrentUserName());
        ListPageVO<PrjPrdPaySchMVO> listPage = new ListPageVO<PrjPrdPaySchMVO>(list, pager.getTotalCount());
        return listPage;
    }

    /**
     * 资方支付表管理
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/getPrjPrdZfPaySchMList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object getPrjPrdZfPaySchMList(HttpServletRequest request, HttpServletResponse response) {
        String currentPage = request.getParameter("page");
        String pageSize = request.getParameter("pagesize");
        String lsCntNo = request.getParameter("lsCntNo");//合同编号
        String cstNm = request.getParameter("cstNm");//客户名称
        String insCode = request.getParameter("insCode"); //第三方机构
        String strDate = request.getParameter("strDate");//开始时间(起租日)
        String endDate = request.getParameter("endDate");//结束时间(起租日)
        String isEnable = request.getParameter("isEnable");//支付表启用状态
        String paySchTypCd = request.getParameter("paySchTypCd");//支付表类型

        Pager page = new Pager();
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setCurrentPage(Integer.parseInt(currentPage));
        }

        if (StringUtils.isNotEmpty(currentPage)) {
            page.setEveryPage(Integer.parseInt(pageSize));
        }
        PrjPrdPaySchMQueryCondition qc = new PrjPrdPaySchMQueryCondition();
        if (StringUtils.isNotBlank(lsCntNo)) {
            qc.setLsCntNo(lsCntNo);
        }
        if (StringUtils.isNotBlank(cstNm)) {
            qc.setCstNm(cstNm);
        }
        if (StringUtils.isNotBlank(insCode)) {
            qc.setInsCode(insCode);
        }
        if (StringUtils.isNotBlank(strDate)) {
            qc.setStrDt(DateUtils.formatStringToDate(strDate, DateUtils.YYYY_MM_DD));
        }

        if (StringUtils.isNotBlank(endDate)) {
            qc.setEndDt(DateUtils.formatStringToDate(endDate, DateUtils.YYYY_MM_DD));
        }

        if (StringUtils.isNotEmpty(isEnable)) {
            qc.setIsEnable(Integer.valueOf(isEnable));
        }
        //默认查我司支付表流水
        if (!StringUtils.isNotBlank(paySchTypCd)) {
            paySchTypCd = "WS";
        }
        qc.setPaySchTypCd(paySchTypCd);
        qc.setUsrId(CurrentThreadContext.getCurrentUserId());
        qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
        qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
        page.setCondition(qc);
        BaseLogUtils.info(logger, "initPrjPrdZfPaySchMList", "初始化PrjPrdZfPaySchM列表页面数据.DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
        Pager pager = null;
        //获取资方支付表数据
        pager = this.prjPrdPaySchMService.selectPrjPrdZfPaySchMMgrListPage(page);

        List<PrjPrdPaySchMVO> list = (List<PrjPrdPaySchMVO>) pager.getResultList();
        BaseLogUtils.info(logger, "getPrjPrdZfPaySchMList", "资管支付表管理list 添加业务线before:" + JSONObject.toJSONString(list), CurrentThreadContext.getCurrentUserName());
        //资管机构名称后添加业务线字典
        if (CollectionUtils.isNotEmpty(list)) {
            //业务线字典List
            List<KeyValueVO> bussinessLineDicList = sysDictionaryApiService.getKvList("REF0048","11000","0000");
            //查询第三方机构
            List<FriBaseInfoVO> friBaseInfoVOList = this.overdueService.getFriBaseInfoList();
            //根据金融机构业务线,设置金融机构名称展示字段值
            FundRasInsNmChangeUtil.insNmShowAddBussinessLineDic(friBaseInfoVOList,bussinessLineDicList);
            if (CollectionUtils.isNotEmpty(friBaseInfoVOList)) {
                for (PrjPrdPaySchMVO prjPrdPaySchMVOTemp : list) {
                    if (StringUtils.isEmpty(prjPrdPaySchMVOTemp.getFundRasInsId())) {
                        continue;
                    }
                    for (FriBaseInfoVO friBaseInfoVOTemp : friBaseInfoVOList) {
                        if (StringUtils.isNotEmpty(friBaseInfoVOTemp.getId()) && StringUtils.isNotEmpty(friBaseInfoVOTemp.getFundRasInsNmShow())
                                && friBaseInfoVOTemp.getId().longValue() == prjPrdPaySchMVOTemp.getFundRasInsId().longValue()) {
                            prjPrdPaySchMVOTemp.setFundRasInsNm(friBaseInfoVOTemp.getFundRasInsNmShow());
                            break;
                        }
                    }
                }
            }
        }
        BaseLogUtils.info(logger, "getPrjPrdZfPaySchMList", "资管支付表管理list 添加业务线after:" + JSONObject.toJSONString(list), CurrentThreadContext.getCurrentUserName());
        ListPageVO<PrjPrdPaySchMVO> listPage = new ListPageVO<PrjPrdPaySchMVO>(list, pager.getTotalCount());
        return listPage;
    }

    /**
     * 根据支付表号获取支付表明细
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/getPrjPrdPaySchMListBypaySchNo.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object getPrjPrdPaySchMListBypaySchNo(HttpServletRequest request, HttpServletResponse response) {
        String paySchNo = request.getParameter("paySchNo");//支付表号
        Pager page = new Pager();
        PrjPrdPaySchMQueryCondition qc = new PrjPrdPaySchMQueryCondition();
        if (StringUtils.isNotBlank(paySchNo)) {
            qc.setPaySchNo(paySchNo);
        }
        qc.setUsrId(CurrentThreadContext.getCurrentUserId());
        qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
        qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
        page.setCondition(qc);
        Pager pager = this.prjPrdPaySchMService.selectPrjPrdPaySchMMgrListPage(page);
        List<PrjPrdPaySchMVO> list = (List<PrjPrdPaySchMVO>) pager.getResultList();
        PrjPrdPaySchMVO prjPrdPaySchMVO = list.get(0);
        ModelAndView mav = new ModelAndView("project/prjprdquatprps/prjPrdQuatPrpsAdd");
        mav.addObject("prjId", prjPrdPaySchMVO.getPrjId());
        mav.addObject("prjPrdDtlId", prjPrdPaySchMVO.getPrjPrdDtlId());
        mav.addObject("prjPrdId", prjPrdPaySchMVO.getPrjPrdId());
        mav.addObject("id", prjPrdPaySchMVO.getId());
        mav.addObject("detailFlag", true);
        return mav;
    }

    /**
     * 根据支付表id调整到支付表详情页面
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/toPrjPrdPaySchMDetailPageBySchId.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object toPrjPrdPaySchMDetailPageBySchId(HttpServletRequest request, HttpServletResponse response) {
        String paySchId = request.getParameter("paySchId");//支付表ID
        Long prjId = null;
        Long prjPrdDtlId = null;
        Long prjPrdId = null;
        PrjPrdPaySchMVO schMVO = this.prjPrdPaySchMService.selectById(Long.valueOf(paySchId));
        PrjPrdDtlQueryCondition dtlQc = new PrjPrdDtlQueryCondition();
        dtlQc.setPaySchId(Long.valueOf(paySchId));
        List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(dtlQc);
        if (CollectionUtils.isNotEmpty(dtlList)) {
            PrjPrdDtlVO dtlVO = dtlList.get(0);
            prjId = dtlVO.getPrjId();
            prjPrdDtlId = dtlVO.getId();
            prjPrdId = dtlVO.getPrjPrdId();
        }
        ModelAndView mav = new ModelAndView("project/prjprdquatprps/prjPrdQuatPrpsAdd");
        mav.addObject("prjId", prjId);
        mav.addObject("prjPrdDtlId", prjPrdDtlId);
        mav.addObject("prjPrdId", prjPrdId);
        mav.addObject("id", schMVO.getId());
        mav.addObject("detailFlag", true);
        return mav;
    }

    /**
     * 支付表管理
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/getPrjPrdPayByPrjId.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object getPrjPrdPayByPrjId(HttpServletRequest request, HttpServletResponse response) {
        String prjId = request.getParameter("prjId");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "");
        PrjPrdPaySchMQueryCondition qc = new PrjPrdPaySchMQueryCondition();
        if (StringUtils.isNotBlank(prjId)) {
            qc.setPrjId(Long.valueOf(prjId));
        }
        qc.setPaySchTypCd(PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_WS);
        List<PrjPrdPaySchMVO> list = this.prjPrdPaySchMService.searchList(qc);
        BaseLogUtils.info(logger, "getPrjPrdPayByPrjId", "初始化PrjPrdPaySchM列表页面数据.DATA:" + JSONObject.toJSONString(list), CurrentThreadContext.getCurrentUserName());
        if (CollectionUtils.isNotEmpty(list)) {
            result.setData(list);
        }
        return result;
    }

    /**
     * 删除数据
     */
    @RequestMapping(value = "/removeByIds.do", method = {RequestMethod.POST})
    @ResponseBody
    public DataResultVO removePrjPrdPaySchMByIds(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String ids = request.getParameter("ids");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
        if (StringUtils.isEmpty(ids)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.info(logger, "removePrjPrdPaySchMByIds", "删除PrjPrdPaySchM数据,主键参数为空!", CurrentThreadContext.getCurrentUserName());
            return result;
        }

        List<Long> idsList = new ArrayList<Long>();
        JSONArray idsArray = JSONArray.fromObject(ids);
        for (Object object : idsArray) {
            idsList.add(Long.valueOf(object.toString()));
        }

        try {
            boolean success = this.prjPrdPaySchMService.removeByIds(idsList);
            if (!success) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_DELETE_FAIL);
                BaseLogUtils.info(logger, "removePrjPrdPaySchMByIds", "删除PrjPrdPaySchM数据失败,ID:" + idsList.toString(), CurrentThreadContext.getCurrentUserName());
            }
            BaseLogUtils.info(logger, "removePrjPrdPaySchMByIds", "删除PrjPrdPaySchM数据成功,ID:" + idsList.toString(), CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.info(logger, "removePrjPrdPaySchMByIds", "删除PrjPrdPaySchM数据失败,ID:" + idsList.toString() + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "removePrjPrdPaySchMByIds", "删除PrjPrdPaySchM数据失败,系统错误.ID:" + idsList.toString() + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }

    /**
     * 得到一条记录
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getById.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object getPrjPrdPaySchMById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String id = request.getParameter("id");
        String prjId = request.getParameter("prjId");
        String prjPrdId = request.getParameter("prjPrdId");
        String prjPrdDtlId = request.getParameter("prjPrdDtlId");
        //资管支付表查看详情
        String zfDetailFlag = request.getParameter("zfDetailFlag");
        if (StringUtils.isNotBlank(prjPrdDtlId) && StringUtils.isBlank(prjPrdId)) {
            PrjPrdDtlVO vo = prjPrdDtlService.selectById(Long.valueOf(prjPrdDtlId));
            if (vo != null) {
                prjPrdId = String.valueOf(vo.getPrjPrdId());
            }
        }
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        PrjPrdPaySchMVO vo = null;
        PrjQuatPrpsCfgMVO quatPrps = null;
        try {
            //根据项目ID查询默认的方案，根据方案查询方案配置，确定产品费用项是否可以修改
//            if (StringUtils.isNotBlank(prjId)) {
//                PrjQuatPrpsQueryCondition qc = new PrjQuatPrpsQueryCondition();
//                qc.setIsFormalPrps(BaseConstant.IS_YESNO_YES);
//                qc.setPrjId(Long.valueOf(prjId));
//                PrjQuatPrpsVO quat = null;
//                List<PrjQuatPrpsVO> quatList = this.prjQuatPrpsService.searchList(qc);
//                if (CollectionUtils.isNotEmpty(quatList)) {
//                    quat = quatList.get(0);
//                    //quatPrps = 	this.prjQuatPrpsCfgMService.selectById(Long.valueOf(quat.getPrpsCfgId()));
//                }
//            }
            if (StringUtils.isEmpty(id)) {
                //商品支付表未拆分，拆分支付表 测算
                vo = this.prjPrdPaySchMService.initPrjPrdPaySchMCalculate(Long.valueOf(prjId), Long.valueOf(prjPrdId), Long.valueOf(prjPrdDtlId));
            } else {
                if("true".equals(zfDetailFlag)){
                    //资管支付表详情页面
                    vo = this.prjPrdPaySchMService.selectPrjPrdPaySchMEnableAndDetailById(Long.valueOf(id));
                } else {
                    //支付表详情页面
                    vo = this.prjPrdPaySchMService.selectPrjPrdPaySchMAndDetailById(Long.valueOf(id));
                }
            }
            if (null == vo) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
                BaseLogUtils.info(logger, "getPrjPrdPaySchMById", "获取PrjPrdPaySchM数据不存在,ID:" + id + "zfDetailFlag:" +zfDetailFlag, CurrentThreadContext.getCurrentUserName());
            }
            PrjBscInfoVO prjBsc = this.prjBscInfoService.selectById(Long.valueOf(prjId));
            PrjPrdBscInfoVO prjPrdBsc = this.prjPrdBscInfoService.selectById(Long.valueOf(prjPrdId));
            if (null != prjPrdBsc.getGuidePc()) {
                prjPrdBsc.setGuidePc(DecimalUtils.convertFenToYuan(prjPrdBsc.getGuidePc().longValue()));
            }
            // prjPrdBsc.setPrdAmt(DecimalUtils.convertFenToYuan(prjPrdBsc.getPrdAmt().longValue()));
            // prjPrdBsc.setRsrvPc(DecimalUtils.convertFenToYuan(prjPrdBsc.getRsrvPc().longValue()));
            vo.setPrjBscInfo(prjBsc);
            vo.setPrjPrdBscInfo(prjPrdBsc);
            // vo.setPrjQuatCfg(quatPrps);

            if (StringUtils.isNotBlank(prjPrdDtlId)) {
                PrjPrdDtlTkVO tk = this.prjPrdDtlTkService.selectById(Long.valueOf(prjPrdDtlId));
                PrjPrdDtlVO dtlVO = this.prjPrdDtlService.selectById(Long.valueOf(prjPrdDtlId));
                if (null != dtlVO) {
                    vo.setDtlVO(dtlVO);
                }
                if (null != tk) {
                    vo.setDtlTkVO(tk);
                }
            }

            if (CollectionUtils.isNotEmpty(vo.getPrjPrdPayDetailList())) {
                ListPageVO<PrjPrdPrpsFeeDetailVO> listPage = new ListPageVO<PrjPrdPrpsFeeDetailVO>(vo.getPrjPrdPayDetailList(), vo.getPrjPrdPayDetailList().size());
                vo.setPrjQuatPrpsPaySchPage(listPage);
            }
            if (CollectionUtils.isNotEmpty(vo.getFeeDetailList())) {
                List<PrjPrdPaySchDVO> list = new ArrayList<PrjPrdPaySchDVO>();
                for (PrjPrdPaySchDVO prjPrdPaySchDVO : vo.getFeeDetailList()) {
                    if (prjPrdPaySchDVO.getFeeClsCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_PRPS)) {
                        //保证金转出备注
                        String remarkForFee = "";
                        CapFeeOutLogQueryCondition condition = new CapFeeOutLogQueryCondition();
                        condition.setPaySchId(prjPrdPaySchDVO.getPaySchId());
                        condition.setPaySchDId(prjPrdPaySchDVO.getId());
                        condition.setFeeTypCd(prjPrdPaySchDVO.getFeeTypCd());
                        List<CapFeeOutLogVO> CapFeeOutLogList = this.capFeeOutLogService.searchList(condition);
                        if (CollectionUtils.isNotEmpty(CapFeeOutLogList)) {
                            int i = 0;
                            for (CapFeeOutLogVO capFeeOutLogVO : CapFeeOutLogList) {
                                i++;
                                remarkForFee += capFeeOutLogVO.getCrtUsrNm() + "-->";
                                remarkForFee += DateUtils.formatDateToString(capFeeOutLogVO.getOutDt(), DateUtils.YYYY_MM_DDHHMMSS) + "-->";
                                remarkForFee += capFeeOutLogVO.getHandleWayCdNm();
                                remarkForFee += BigDecimal.valueOf(capFeeOutLogVO.getOutAmt()).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP) + "元-->";
                                remarkForFee += capFeeOutLogVO.getOutRem();
                                if (i < CapFeeOutLogList.size()) {
                                    remarkForFee += "---";
                                }
                            }
                        }
                        prjPrdPaySchDVO.setRemarkForFee(remarkForFee);
                        list.add(prjPrdPaySchDVO);
                    }
                }
                ListPageVO<PrjPrdPaySchDVO> listPage = new ListPageVO<PrjPrdPaySchDVO>(list, list.size());
                // ListPageVO<PrjPrdPaySchDVO> listPage = new ListPageVO<PrjPrdPaySchDVO>(vo.getFeeDetailList(), vo.getFeeDetailList().size());
                vo.setFeeDetailListPage(listPage);
            }
            result.setData(vo);
            BaseLogUtils.info(logger, "getPrjPrdPaySchMById", "获取PrjPrdPaySchM数据成功,ID:" + id, CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.info(logger, "getPrjPrdPaySchMById", "获取PrjPrdPaySchM数据失败,ID:" + id + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "getPrjPrdPaySchMById", "获取PrjPrdPaySchM数据失败,系统错误.ID:" + id + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
        }
        return result;
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/addPrjPrdPayRickDep.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object addPrjPrdPayRickDep(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
        PrjPrdPaySchDVO detail = null;//获取参数
        String prjPrdSchId = request.getParameter("prjPrdSchId");
        String feeAmt = request.getParameter("feeAmt");
        // String payDt = request.getParameter("payDt");
        String rem = request.getParameter("rem");
        String fileParams = request.getParameter("fileParams");
        Long prjPrdSchMId = null;
        DataResultVO resultVO = null;
        try {
            detail = new PrjPrdPaySchDVO();
            if (StringUtils.isNotBlank(prjPrdSchId)) {
                detail.setPaySchId(Long.valueOf(prjPrdSchId));
            }
            detail.setFeeRem(rem);
            if (StringUtils.isBlank(feeAmt)) {
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "费用金额不能为空!");
            }
            detail.setFeeAmt(DecimalUtils.convertYuanToFen(Double.valueOf(feeAmt)).doubleValue());
            detail.setArAmt(DecimalUtils.convertYuanToFen(Double.valueOf(feeAmt)));
            detail.setPayPd(PrjQuatPrpsConstant.CODE_PRJ_PRD_FEE_PD);
            detail.setFeeTypCd(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_RICK_DEP);
            detail.setCapFlow(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CASH_FLOW_IN);
            detail.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_OTH);
            detail.setFeeClsCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_PRPS);
            List<SysUlFilesRecVO> fileList = new ArrayList<SysUlFilesRecVO>();
            if (StringUtils.isBlank(fileParams)) {
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "请上传汇款到账查询截图!");
            }
            if (StringUtils.isNotBlank(fileParams)) {
                fileList = JSON.parseArray(fileParams, SysUlFilesRecVO.class);
                for (SysUlFilesRecVO sysUlFilesRecVO : fileList) {
                    sysUlFilesRecVO.setSysCd(CurrentThreadContext.getCurrentSysCd());
                    sysUlFilesRecVO.setOrgCd(PrjBscInfoConstant.CODE_PRJ_FILE_DEF_ORG);
                    sysUlFilesRecVO.setAbsLocPath(PropertiesCacheUtils.getProperty(UploadConstant.UPLOAD_ROOT_PATH) + sysUlFilesRecVO.getFilePath());

                }
                detail.setFileList(fileList);
            }
            detail.setIsDel(PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);//流程中间状态
            resultVO = this.prjPrdPaySchDService.addPrjPrdPayRickDep(detail);

            BaseLogUtils.info(logger, "addPrjPrdPayRickDep", "保存风险保证金数据成功," + ".DATA:" + JSONObject.toJSONString(detail), CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            resultVO = new DataResultVO();
            resultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            resultVO.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.info(logger, "addPrjPrdPayRickDep", "保存风险保证金数据失败.DATA:" + JSONObject.toJSONString(detail) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            resultVO = new DataResultVO();
            resultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            resultVO.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.error(logger, "addPrjPrdPayRickDep", "保存风险保证金数据失败,系统错误.DATA:" + JSONObject.toJSONString(detail) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return resultVO;
    }


    /**
     * 校验是否可以发起结清流程
     * @param request
     * @return
     * @throws BaseException
     */
    @RequestMapping(value = "/checkPrjPaySchFlag.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object checkPrjPaySchFlag(HttpServletRequest request) throws BaseException {
        DataResultVO resultVO = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        String paySchId = request.getParameter("paySchId");
        String sett = request.getParameter("sett");//获取结清方式
        try {
            if (StringUtils.isEmpty(paySchId)) {
                throw new BaseException(SysLogConstant.LOG_CMM_SYS_ERROR, "请选择支付表!");
            }
            if (StringUtils.isEmpty(sett)) {
                throw new BaseException(SysLogConstant.LOG_CMM_SYS_ERROR, "结清类型不能为空!");
            }
            int flowTyp = prjPrdPaySchMService.prjPrdPayApplySettFlag(Long.valueOf(paySchId), sett);
            resultVO.setData(flowTyp);
        } catch (BaseException ex) {
            resultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            resultVO.setInfo(ex.getMessage());
            BaseLogUtils.newLogger("检查是否可以发起流程失败.ERROR:").setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
        } catch (Exception ex) {
            resultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            resultVO.setInfo(ex.getMessage());
            BaseLogUtils.newLogger("检查是否可以发起流程失败,系统错误.ERROR:").setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
        }
        return resultVO;
    }


    /**
     * 发起正常结清流程
     */
    @RequestMapping(value = "/applyNormalSett.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object applyNormalSett(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        PrjPrdPaySchMVO pay = null;//获取参数
        String prjPrdSchId = request.getParameter("paySchId");
        String totalSettAmt = request.getParameter("totalSettAmt");//最终结清款
        String payPd = request.getParameter("payPd");//结清期数
        // 2019年5月20日16:52:54 REQ-3199 资管结清添加参数：0-单台结清 1-全部结清
        String isAllStl = request.getParameter("isAllStl");
        DataResultVO resultVO = null;
        List<PrjPrdPaySchDVO> entityList = null;//获取参数
        try {
            // 资管结清不走此校验
            if (StringUtils.isNotBlank(prjPrdSchId) && StringUtils.isEmpty(isAllStl)) {
                prjPrdPaySchMService.prjPrdPayApplySettFlag(Long.valueOf(prjPrdSchId), PrjPrdPaySchMConstant.PRJ_PRD_Pay_SCH_M_NORMAL);
            }

            PrjPrdPaySchMVO prjPrdPaySchMVO = this.prjPrdPaySchMService.selectById(Long.valueOf(prjPrdSchId));
            PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(prjPrdPaySchMVO.getPrjId());//查询所属事业部

            pay = new PrjPrdPaySchMVO();
            pay.setPrjId(prjPrdPaySchMVO.getPrjId());
            if (StringUtils.isNotEmpty(prjPrdSchId)) {
                pay.setId(Long.valueOf(prjPrdSchId));
            }
            if (StringUtils.isNotBlank(payPd)) {
                pay.setStlPd(Integer.valueOf(payPd));
            }
            if (StringUtils.isNotBlank(isAllStl)) {
                pay.setIsAllStl(isAllStl);
            }
            //发起结清剔除    结清费用项:settFeeList
            request.removeAttribute("settFeeList");

            entityList = this.getRequestParamForSettFeeList(request);//获取参数

            //判断是否是重卡事业部
            if (prjBscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_ZK)) {
                InsFeeDeductRecQueryCondition qc = new InsFeeDeductRecQueryCondition();
                qc.setPaySchId(prjPrdPaySchMVO.getId());
                List<InsFeeDeductRecVO> list = this.insFeeDeductRecService.searchList(qc);
                if (CollectionUtils.isNotEmpty(list)) {
                    for (InsFeeDeductRecVO vo : list) {
                        //判断支付表单是否转正常
                        if (vo.getDeductStsCd().equals(InsFeeDeductRecConstant.CODE_DEDUCT_STS_CD_2)) {
                            throw new BaseException(SysLogConstant.LOG_CMM_SYS_ERROR, "保险违约金转正常中，请保险违约金转正常之后再操作!");
                        }
                    }
                }
            }

            if (CollectionUtils.isNotEmpty(entityList)) {
                pay.setFeeDetailList(entityList);
            }
            if (StringUtils.isNotBlank(totalSettAmt)) {
                pay.setStlAmt(DecimalUtils.convertYuanToFen(Double.valueOf(totalSettAmt)));
            }
            resultVO = this.prjPrdPaySchMService.addFileAndApplyNormalSett(pay);

            BaseLogUtils.info(logger, "applyNormalSett", "发起正常结清流程成功," + ".DATA:" + JSONObject.toJSONString(pay), CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            resultVO = new DataResultVO();
            resultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            resultVO.setInfo(ex.getMessage());
            BaseLogUtils.newLogger("发起正常结清流程失败.").setBussinessId(prjPrdSchId).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
            return resultVO;
        } catch (Exception ex) {
            resultVO = new DataResultVO();
            resultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            resultVO.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.newLogger("发起正常结清流程失败,系统错误.").setBussinessId(prjPrdSchId).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
            return resultVO;
        }
        return resultVO;
    }

    /**
     * 发起提前结清流程
     */
    @RequestMapping(value = "/applyPreSett.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object applyPreSett(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        //DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
        PrjPrdPaySchMVO pay = null;//获取参数
        String prjPrdSchId = request.getParameter("paySchId");
        //String payList = request.getParameter("payList");
        String totalSettAmt = request.getParameter("totalSettAmt");//最终结清款
        String payPd = request.getParameter("payPd");//结清期数
        // 2019年5月20日16:52:54 REQ-3199 资管结清添加参数：0-单台结清 1-全部结清
        String isAllStl = request.getParameter("isAllStl");
        DataResultVO resultVO = null;
        List<PrjPrdPaySchDVO> entityList = null;
        try {
            // 资管结清不走此校验
            if (StringUtils.isNotBlank(prjPrdSchId) && StringUtils.isEmpty(isAllStl)) {
                prjPrdPaySchMService.prjPrdPayApplySettFlag(Long.valueOf(prjPrdSchId), PrjPrdPaySchMConstant.PRJ_PRD_Pay_SCH_M_PRE);
            }

            PrjPrdPaySchMVO prjPrdPaySchMVO = this.prjPrdPaySchMService.selectById(Long.valueOf(prjPrdSchId));
            PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(prjPrdPaySchMVO.getPrjId());//查询所属事业部

            pay = new PrjPrdPaySchMVO();
            pay.setPrjId(prjPrdPaySchMVO.getPrjId());
            if (StringUtils.isNotEmpty(prjPrdSchId)) {
                pay.setId(Long.valueOf(prjPrdSchId));
            }
            if (StringUtils.isNotBlank(isAllStl)) {
                pay.setIsAllStl(isAllStl);
            }

            // 客户经理发起结清不允许添加费用项，这里去除request中的settFeeList
            request.removeAttribute("settFeeList");

            entityList = this.getRequestParamForSettFeeList(request);//获取参数
            if (CollectionUtils.isNotEmpty(entityList)) {
                pay.setFeeDetailList(entityList);
            }

            //判断是否是重卡事业部
            if (prjBscInfoVO.getBuOrgCd().equals(PrjBscInfoConstant.CODE_BU_ORG_CD_ZK)) {
                InsFeeDeductRecQueryCondition qc = new InsFeeDeductRecQueryCondition();
                qc.setPaySchId(prjPrdPaySchMVO.getId());
                List<InsFeeDeductRecVO> list = this.insFeeDeductRecService.searchList(qc);
                if (CollectionUtils.isNotEmpty(list)) {
                    for (InsFeeDeductRecVO vo : list) {
                        //判断支付表单是否转正常
                        if (vo.getDeductStsCd().equals(InsFeeDeductRecConstant.CODE_DEDUCT_STS_CD_2)) {
                            throw new BaseException(SysLogConstant.LOG_CMM_SYS_ERROR, "保险违约金转正常中，请保险违约金转正常之后再操作!");
                        }
                    }
                }
            }

            if (StringUtils.isNotBlank(totalSettAmt)) {
                pay.setStlAmt(DecimalUtils.convertYuanToFen(Double.valueOf(totalSettAmt)));
            }
            if (StringUtils.isNotBlank(payPd)) {
                pay.setStlPd(Integer.valueOf(payPd));
            }
            resultVO = this.prjPrdPaySchMService.addFileAndPreNormalSett(pay);

            BaseLogUtils.info(logger, "applyNormalSett", "发起提前结清流程成功," + ".DATA:" + JSONObject.toJSONString(pay), CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            resultVO = new DataResultVO();
            resultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            resultVO.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.newLogger("发起提前结清流程失败.").setBussinessId(prjPrdSchId).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
            return resultVO;
        } catch (Exception ex) {
            resultVO = new DataResultVO();
            resultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            resultVO.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.newLogger("发起提前结清流程失败.").setBussinessId(prjPrdSchId).setThrowable(ex).error(LogExceptionEnum.COMMON_CODE_0002);
            return resultVO;
        }
        return resultVO;
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object addPrjPrdPaySchM(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
        PrjPrdPaySchMVO entity = null;//获取参数
        String id = request.getParameter("id");
        Long prjPrdSchMId = null;
        try {
            entity = this.getRequestParamForPrjPrdPaySchM(request);//获取参数
            if (StringUtils.isNotBlank(id)) {
                prjPrdSchMId = Long.valueOf(id);
                //修改
                this.prjPrdPaySchMService.modify(entity);
                result.setSuccess(BaseConstant.IS_YESNO_YES);
                result.setInfo(SysLogConstant.LOG_CMM_UPDATE_SUCC);
            } else {
                //添加
                prjPrdSchMId = this.prjPrdPaySchMService.add(entity);
            }
            result.setData(prjPrdSchMId);
            BaseLogUtils.info(logger, "addPrjPrdPaySchM", "保存PrjPrdPaySchM数据成功,ID:" + id + ".DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "addPrjPrdPaySchM", "保存PrjPrdPaySchM数据失败.DATA:" + JSONObject.toJSONString(entity) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.error(logger, "addPrjPrdPaySchM", "保存PrjPrdPaySchM数据失败,系统错误.DATA:" + JSONObject.toJSONString(entity) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/modify.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object modifyPrjPrdPaySchM(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
        PrjPrdPaySchMVO entity = null;
        try {
            entity = this.getRequestParamForPrjPrdPaySchM(request);
            if (entity.getId() == null) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
                BaseLogUtils.info(logger, "modifyPrjPrdPaySchM", "修改PrjPrdPaySchM信息,主键参数为空！.", CurrentThreadContext.getCurrentUserName());
                return result;
            }

            boolean success = this.prjPrdPaySchMService.modify(entity);
            if (!success) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_UPDATE_FAIL);
                BaseLogUtils.info(logger, "modifyPrjPrdPaySchM", "修改PrjPrdPaySchM数据失败.DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
                return result;
            }
            BaseLogUtils.info(logger, "modifyPrjPrdPaySchM", "修改PrjPrdPaySchM数据成功.DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.info(logger, "modifyPrjPrdPaySchM", "修改PrjPrdPaySchM数据失败.DATA:" + JSONObject.toJSONString(entity) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.error(logger, "modifyPrjPrdPaySchM", "修改PrjPrdPaySchM数据失败,系统错误.DATA:" + JSONObject.toJSONString(entity) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }

    /*
     * 保存起租日（仅根据id保存单个值）
     */
    @RequestMapping(value = "/toModifylsDt.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object toModifylsDt(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
        PrjPrdPaySchMVO entity = new PrjPrdPaySchMVO();
        String id = request.getParameter("id");//主键
        String lsDt = request.getParameter("lsDt");
        Long ids = Long.valueOf(id);
        Date lsDts = DateUtils.formatStringToDate(lsDt, "yyyy-MM-dd");
        this.prjPrdPaySchMService.modifylsDt(ids, lsDts);

        BaseLogUtils.info(logger, "modifyPrjPrdPaySchM", "修改PrjPrdPaySchM数据成功.DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
        return result;
    }

    /**
     * 保存起租日修改
     */
    @RequestMapping(value = "/modifyLsDt.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object modifyLsDt(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
        String id = request.getParameter("id");
        String lsDt = request.getParameter("lsDt");
        PrjPrdPaySchMVO entity = null;
        try {
            if (id == null) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
                BaseLogUtils.info(logger, "modifyPrjPrdPaySchM", "修改PrjPrdPaySchM信息,主键参数为空！.", CurrentThreadContext.getCurrentUserName());
                return result;
            }
            entity = this.prjPrdPaySchMService.selectById(Long.valueOf(id));
            PrjBscInfoVO prjBscInfo = this.prjBscInfoService.selectById(entity.getPrjId());
            entity.setBuOrgCd(prjBscInfo.getBuOrgCd());
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            entity.setLsDt(sdf.parse(lsDt));
            boolean success = this.prjPrdPaySchMService.modifyLsDt(entity);
            if (!success) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_UPDATE_FAIL);
                BaseLogUtils.info(logger, "modifyPrjPrdPaySchM", "修改PrjPrdPaySchM数据失败.DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
                return result;
            }
            BaseLogUtils.info(logger, "modifyPrjPrdPaySchM", "修改PrjPrdPaySchM数据成功.DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.info(logger, "modifyPrjPrdPaySchM", "修改PrjPrdPaySchM数据失败.DATA:" + JSONObject.toJSONString(entity) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.error(logger, "modifyPrjPrdPaySchM", "修改PrjPrdPaySchM数据失败,系统错误.DATA:" + JSONObject.toJSONString(entity) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }

    /**
     * 根据客户经理查询项目产品信息 -非我司渠道保险支公司
     */
    @RequestMapping(value = "/selectPrjPrdList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object selectPrjPrdList(HttpServletRequest request, HttpServletResponse response) {
        PrjPrdPaySchMQueryCondition qc = new PrjPrdPaySchMQueryCondition();
        //设置查询条件？
        qc.setCstMgrId(CurrentThreadContext.getCurrentUserId());
        String paySchNo = request.getParameter("paySchNo");//支付表编号
        if (StringUtils.isNotEmpty(paySchNo)) {
            qc.setPaySchNo(paySchNo);
        }
        BaseLogUtils.info(logger, "initPrjPrdPaySchMList", "根据客户经理查询项目产品信息.DATA:" + JSONObject.toJSONString(qc), CurrentThreadContext.getCurrentUserName());
        List<PrjPrdPaySchMVO> list = this.prjPrdPaySchMService.selectPrjPrdList(qc);
        PrjPrdPaySchMVO vo = new PrjPrdPaySchMVO();
        vo.setPrjPrdDtlId(1111L);
        vo.setPaySchNo("NO22222");
        vo.setPrdNm("测试产品");
        vo.setPrjNm("测试项目");
        vo.setCstNm("客户名称");
        list.add(vo);
        ListPageVO<PrjPrdPaySchMVO> listPage = new ListPageVO<PrjPrdPaySchMVO>(list, list.size());
        return listPage;
    }

    /**
     * 获取请求参数
     *
     * @param request 请求
     * @return
     */
    private PrjPrdPaySchMVO getRequestParamForPrjPrdPaySchM(HttpServletRequest request) throws BaseException {
        //TODO 获取参数
        String id = request.getParameter("id");//主键
        String prjPrdDtlId = request.getParameter("prjPrdDtlId");
        String totLsItmAmt = request.getParameter("totLsItmAmt");
        String contAmt = request.getParameter("contAmt");
        String lsPd = request.getParameter("lsPd");
        String lsPdUntCd = request.getParameter("lsPdUntCd");
        String annIntRatePct = request.getParameter("annIntRatePct");
        String intRateRsPct = request.getParameter("intRateRsPct");
        String payWayCd = request.getParameter("payWayCd");
        String actLsAmt = request.getParameter("actLsAmt");
        String irrPct = request.getParameter("irrPct");
        String eachEstRntAmt = request.getParameter("eachEstRntAmt");
        String lsCalWayCd = request.getParameter("lsCalWayCd");
        String intRateWayCd = request.getParameter("intRateWayCd");
        String lsCoe = request.getParameter("lsCoe");
        String dpstHdlWayCd = request.getParameter("dpstHdlWayCd");
        String expHdlWayCd = request.getParameter("expHdlWayCd");
        String noPayWayCd = request.getParameter("noPayWayCd");
        String paySchNo = request.getParameter("paySchNo");
        String prjId = request.getParameter("prjId");
        String cstId = request.getParameter("cstId");
        String payList = request.getParameter("payList");
        String feeDetailList = request.getParameter("feeDetailList");
        PrjPrdPaySchMVO prjPrdPay = new PrjPrdPaySchMVO();

        prjPrdPay.setPrjId(Long.valueOf(prjId));

        //项目基本信息
        PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(Long.valueOf(prjId));

        //当前事业部
        String buOrgCd =  prjBscInfoVO.getBuOrgCd();

        //项目类型
        String prjTypCd = prjBscInfoVO.getPrjTypCd();

        //组织架构
        BaseLogUtils.newLogger(String.format("支付表测算或保存，当前事业部:%s,项目类型:%s",buOrgCd,prjTypCd)).info();

        if (StringUtils.isNotBlank(cstId)) {
            prjPrdPay.setCstId(Long.valueOf(cstId));
        }
        if (StringUtils.isNotBlank(irrPct)) {
            prjPrdPay.setIrrPct(Double.valueOf(irrPct));
        }

        if (StringUtils.isNotBlank(paySchNo)) {
            prjPrdPay.setPaySchNo(paySchNo);
        }
        if (StringUtils.isNotBlank(prjPrdDtlId)) {
            prjPrdPay.setPrjPrdDtlId(Long.valueOf(prjPrdDtlId));
        }
        if (StringUtils.isNotBlank(lsCoe)) {
            prjPrdPay.setLsCoe(Double.valueOf(lsCoe));
        }
        if (StringUtils.isNotBlank(intRateRsPct)) {
            prjPrdPay.setIntRateRsPct(Double.valueOf(intRateRsPct));
        }
        if (StringUtils.isNotBlank(actLsAmt)) {
            prjPrdPay.setActLsAmt(DecimalUtils.convertYuanToFen(Double.valueOf(actLsAmt)).doubleValue());
        }
        if (StringUtils.isNotBlank(eachEstRntAmt)) {
            prjPrdPay.setEachEstRntAmt(DecimalUtils.convertYuanToFen(Double.valueOf(eachEstRntAmt)).doubleValue());
        }

        if (StringUtils.isEmpty(intRateWayCd)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "租赁年利率计算单位不能为空!");
        }
        prjPrdPay.setIntRateWayCd(intRateWayCd);
        if (StringUtils.isEmpty(lsPdUntCd)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "租赁期数单位不能为空!");
        }
        prjPrdPay.setLsPdUntCd(lsPdUntCd);
        if (StringUtils.isEmpty(totLsItmAmt)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "租赁物件总价值不能为空!");
        }
        if (!StringUtils.isUnsignedNumeric(totLsItmAmt)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "租赁物件总价值应为数字!");
        }
        prjPrdPay.setTotLsItmAmt(DecimalUtils.convertYuanToFen(Double.valueOf(totLsItmAmt)).doubleValue());
        if (StringUtils.isEmpty(contAmt)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "合同总额不能为空!");
        }
        if (!StringUtils.isUnsignedNumeric(contAmt)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "合同总额应为数字!");
        }
        prjPrdPay.setContAmt(DecimalUtils.convertYuanToFen(Double.valueOf(contAmt)).doubleValue());
        if (StringUtils.isEmpty(lsPd)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "租赁期数不能为空!");
        }
        if (!StringUtils.isNumeric(lsPd)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "租赁期数应为数字!");
        }
        prjPrdPay.setLsPd(Integer.valueOf(lsPd));
        if (StringUtils.isEmpty(annIntRatePct)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "租赁年利率不能为空!");
        }
        if (!StringUtils.isUnsignedNumeric(annIntRatePct)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "租赁年利率应为数字!");
        }
        prjPrdPay.setAnnIntRatePct(Double.valueOf(annIntRatePct));
        if (StringUtils.isEmpty(payWayCd)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "支付方式不能为空!");
        }
        prjPrdPay.setPayWayCd(payWayCd);
        if (StringUtils.isEmpty(lsCalWayCd)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "租赁计算方式不能为空!");
        }
        prjPrdPay.setLsCalWayCd(lsCalWayCd);
        if (StringUtils.isEmpty(dpstHdlWayCd)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "保证金处理方式不能为空!");
        }
        prjPrdPay.setDpstHdlWayCd(dpstHdlWayCd);
        if (StringUtils.isEmpty(expHdlWayCd)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "租赁期满处理方式不能为空!");
        }
        prjPrdPay.setExpHdlWayCd(expHdlWayCd);

        List<PrjPrdPaySchDVO> feeList = new ArrayList<PrjPrdPaySchDVO>();
        double firstAmt = 0;
        if (StringUtils.isNotBlank(feeDetailList)) {
            feeList = JSON.parseArray(feeDetailList, PrjPrdPaySchDVO.class);
            for (PrjPrdPaySchDVO prjPrdPaySchDVO : feeList) {
                prjPrdPaySchDVO.setFeeClsCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_PRPS);
                prjPrdPaySchDVO.setFeeAmt(DecimalUtils.convertYuanToFen(prjPrdPaySchDVO.getFeeAmt()).doubleValue());
                //prjPrdPaySchDVO.setArAmt(prjPrdPaySchDVO.getFeeAmt().longValue());
                if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_DOWNPAY)) {
                    firstAmt = prjPrdPaySchDVO.getFeeAmt();
                }

                //供应商返利
                if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_08)) {
                    double splBack = prjPrdPaySchDVO.getFeeAmt();

                    //  重卡事业部传统业务/城配业务
                    if (PrjBscInfoConstant.CODE_BU_ORG_CD_ZK.equals(buOrgCd) &&StringUtils.isNotBlank(prjTypCd) && (PrjBscInfoConstant.PRJ_TYP_CD_CPYW.equals(prjTypCd)  || PrjBscInfoConstant.PRJ_TYP_CD_CTYW.equals(prjTypCd))) {

                        if (splBack > 0) {
                            throw new BaseException("供应商返利金额大于0");
                        }
                    }
                }

                if(prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_49)) {
                   double salBack = prjPrdPaySchDVO.getFeeAmt();

                    //  重卡事业部传统业务/城配业务
                    if (PrjBscInfoConstant.CODE_BU_ORG_CD_ZK.equals(buOrgCd) &&StringUtils.isNotBlank(prjTypCd) && (PrjBscInfoConstant.PRJ_TYP_CD_CPYW.equals(prjTypCd)  || PrjBscInfoConstant.PRJ_TYP_CD_CTYW.equals(prjTypCd))) {

                        if (salBack > 0) {
                            throw new BaseException("销售返利金额大于0");
                        }
                    }
                }

            }
            for (PrjPrdPaySchDVO prjPrdPaySch : feeList) {
                if ((!prjPrdPaySch.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_DOWNPAY)) && prjPrdPaySch.getIsFixedAmt().equals(BaseConstant.IS_YESNO_NO)) {
                    double pct = ProjectUtils.getPctByAmt(prjPrdPay.getTotLsItmAmt(), prjPrdPay.getContAmt(), firstAmt, prjPrdPaySch.getCalBaseCd(), prjPrdPaySch.getFeeAmt());
                    prjPrdPaySch.setFeePct(pct);
                }
            }
            prjPrdPay.setFeeDetailList(feeList);
        }
        List<PrjPrdPrpsFeeDetailVO> feePayList = new ArrayList<PrjPrdPrpsFeeDetailVO>();
        if (StringUtils.isNotBlank(payList)) {
            feePayList = JSON.parseArray(payList, PrjPrdPrpsFeeDetailVO.class);
            for (PrjPrdPrpsFeeDetailVO prjPrdPrpsFeeDetailVO : feePayList) {
                prjPrdPrpsFeeDetailVO.setRemPrinAmt(DecimalUtils.convertYuanToFen(prjPrdPrpsFeeDetailVO.getRemPrinAmt()).doubleValue());
                prjPrdPrpsFeeDetailVO.setRntAmt(DecimalUtils.convertYuanToFen(prjPrdPrpsFeeDetailVO.getRntAmt()).doubleValue());
                prjPrdPrpsFeeDetailVO.setPrinAmt(DecimalUtils.convertYuanToFen(prjPrdPrpsFeeDetailVO.getPrinAmt()).doubleValue());
                prjPrdPrpsFeeDetailVO.setIntAmt(DecimalUtils.convertYuanToFen(prjPrdPrpsFeeDetailVO.getIntAmt()).doubleValue());
            }
            prjPrdPay.setPrjPrdPayDetailList(feePayList);
        }
        List<PrjPrdPaySchDVO> prjPrdPaySchDList = new ArrayList<PrjPrdPaySchDVO>();
        for (PrjPrdPrpsFeeDetailVO payDetail : feePayList) {
            PrjPrdPaySchDVO intPay = new PrjPrdPaySchDVO();
            intPay.setFeeAmt(payDetail.getIntAmt().doubleValue());
            intPay.setArAmt(payDetail.getIntAmt().longValue());
            intPay.setCrtTm(new Date());
            intPay.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
            intPay.setFeeTypCd(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_INT_PRICE);
            intPay.setPayPd(payDetail.getPayPd());
            intPay.setMdfTm(new Date());
            intPay.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
            intPay.setCapFlow(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CASH_FLOW_IN);
            PrjPrdPaySchDVO prinPay = new PrjPrdPaySchDVO();
            prinPay.setFeeAmt(payDetail.getPrinAmt().doubleValue());
            prinPay.setArAmt(payDetail.getPrinAmt().longValue());
            prinPay.setCrtTm(new Date());
            prinPay.setPayPd(payDetail.getPayPd());
            prinPay.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
            prinPay.setFeeTypCd(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_PRINT_PRICE);
            prinPay.setMdfTm(new Date());
            prinPay.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
            prinPay.setCapFlow(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CASH_FLOW_IN);

            PrjPrdPaySchDVO remPrinPay = new PrjPrdPaySchDVO();
            remPrinPay.setFeeAmt(payDetail.getRemPrinAmt().doubleValue());
            remPrinPay.setArAmt(payDetail.getRemPrinAmt().longValue());
            remPrinPay.setPayPd(payDetail.getPayPd());
            remPrinPay.setCrtTm(new Date());
            remPrinPay.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
            remPrinPay.setFeeTypCd(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_REMPRIN_PRICE);
            remPrinPay.setMdfTm(new Date());
            remPrinPay.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
            remPrinPay.setCapFlow(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CASH_FLOW_IN);

            PrjPrdPaySchDVO rntPay = new PrjPrdPaySchDVO();
            rntPay.setFeeAmt(payDetail.getRntAmt().doubleValue());
            rntPay.setArAmt(payDetail.getRntAmt().longValue());
            rntPay.setPayPd(payDetail.getPayPd());
            rntPay.setCrtTm(new Date());
            rntPay.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
            rntPay.setFeeTypCd(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_RNT_PRICE);
            rntPay.setMdfTm(new Date());
            rntPay.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
            rntPay.setCapFlow(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CASH_FLOW_IN);

            prjPrdPaySchDList.add(rntPay);
            prjPrdPaySchDList.add(intPay);
            prjPrdPaySchDList.add(prinPay);
            prjPrdPaySchDList.add(remPrinPay);
        }
        prjPrdPay.setPrjPrdPaySchDList(prjPrdPaySchDList);
        Date tm = new Date();
        if (StringUtils.isNotBlank(id)) {
            prjPrdPay.setId(Long.valueOf(id));
            prjPrdPay.setMdfTm(tm);
            prjPrdPay.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
        } else {
            prjPrdPay.setCrtTm(tm);
            prjPrdPay.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
        }

        return prjPrdPay;
    }

    private List<PrjPrdPaySchDVO> getRequestParamForSettFeeList(HttpServletRequest request) throws BaseException {
        List<PrjPrdPaySchDVO> feeList = new ArrayList<PrjPrdPaySchDVO>();
        String settFeeList = request.getParameter("settFeeList");//新添加的结清费用项
        String paySchId = request.getParameter("paySchId");//支付表ID
        String settFlag = request.getParameter("settFlag");
        String discountAmt = request.getParameter("discountAmt");
        String breachAmt = request.getParameter("breachAmt");//违约金
        if (StringUtils.isNotBlank(settFeeList)) {
            feeList = JSON.parseArray(settFeeList, PrjPrdPaySchDVO.class);
            for (PrjPrdPaySchDVO prjPrdPaySchDVO : feeList) {
                if (StringUtils.isBlank(prjPrdPaySchDVO.getFeeTypCd())) {
                    throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "添加的费用类型不能为空!");
                }
                if (null == prjPrdPaySchDVO.getFeeAmt()) {
                    throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "添加的费用金额不能为空!");
                }
                if (StringUtils.isNotBlank(paySchId)) {
                    prjPrdPaySchDVO.setPaySchId(Long.valueOf(paySchId));
                }
                if (StringUtils.isBlank(prjPrdPaySchDVO.getFeeClsCd())) {
                    prjPrdPaySchDVO.setFeeClsCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_SETT);
                }
                prjPrdPaySchDVO.setFeeAmt(DecimalUtils.convertYuanToFen(prjPrdPaySchDVO.getFeeAmt()).doubleValue());
                /*if (null == prjPrdPaySchDVO.getArAmt()) {
                    prjPrdPaySchDVO.setArAmt(prjPrdPaySchDVO.getFeeAmt().longValue());
                }*/

                //费用金额不对修改
                prjPrdPaySchDVO.setArAmt(prjPrdPaySchDVO.getFeeAmt().longValue());

                prjPrdPaySchDVO.setPayPd(PrjQuatPrpsConstant.CODE_PRJ_PRD_PAY_PD);
                prjPrdPaySchDVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
                prjPrdPaySchDVO.setMdfTm(new Date());
                prjPrdPaySchDVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
                prjPrdPaySchDVO.setCrtTm(new Date());
                prjPrdPaySchDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_OTH);
                prjPrdPaySchDVO.setIsDel(BaseConstant.IS_YESNO_NO);
            }
        }
        //提前结清加入默认的优惠费用项
        if (StringUtils.isNotBlank(settFlag) && settFlag.equals(PrjPrdPaySchMConstant.PRJ_PRD_Pay_SCH_M_PRE)) {
            if (StringUtils.isNotBlank(discountAmt)) {
                PrjPrdPaySchDVO prjPrdPaySchDDTO = new PrjPrdPaySchDVO();
                prjPrdPaySchDDTO.setFeeAmt(DecimalUtils.convertYuanToFen(Double.valueOf(discountAmt)).doubleValue());
                prjPrdPaySchDDTO.setArAmt(DecimalUtils.convertYuanToFen(Double.valueOf(discountAmt)));
                prjPrdPaySchDDTO.setIsFixedAmt(BaseConstant.IS_YESNO_YES);
                prjPrdPaySchDDTO.setFeeClsCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_SETT);
                prjPrdPaySchDDTO.setPayPd(PrjQuatPrpsConstant.CODE_PRJ_PRD_PAY_PD);
                prjPrdPaySchDDTO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_OTH);
                prjPrdPaySchDDTO.setIsDel(BaseConstant.IS_YESNO_NO);
                prjPrdPaySchDDTO.setFeeTypCd(PrjQuatPrpsFeeConstant.FEE_TYP_CD_201);
                prjPrdPaySchDDTO.setCapFlow(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CASH_FLOW_OUT);
                prjPrdPaySchDDTO.setIsSysDef(BaseConstant.IS_YESNO_YES);
                prjPrdPaySchDDTO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
                prjPrdPaySchDDTO.setMdfTm(new Date());
                prjPrdPaySchDDTO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
                prjPrdPaySchDDTO.setCrtTm(new Date());
                prjPrdPaySchDDTO.setPaySchId(Long.valueOf(paySchId));
                feeList.add(prjPrdPaySchDDTO);
            }
            if (StringUtils.isNotBlank(breachAmt)) {
                //违约金
                PrjPrdPaySchDVO prjPrdPaySchDVO = new PrjPrdPaySchDVO();
                prjPrdPaySchDVO.setFeeAmt(DecimalUtils.convertYuanToFen(Double.valueOf(breachAmt)).doubleValue());
                prjPrdPaySchDVO.setArAmt(DecimalUtils.convertYuanToFen(Double.valueOf(breachAmt)));
                prjPrdPaySchDVO.setIsFixedAmt(BaseConstant.IS_YESNO_YES);
                prjPrdPaySchDVO.setFeeClsCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_SETT);
                prjPrdPaySchDVO.setPayPd(PrjQuatPrpsConstant.CODE_PRJ_PRD_PAY_PD);
                prjPrdPaySchDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_OTH);
                prjPrdPaySchDVO.setIsDel(BaseConstant.IS_YESNO_NO);
                prjPrdPaySchDVO.setFeeTypCd(PrjQuatPrpsFeeConstant.FEE_TYP_CD_103);
                prjPrdPaySchDVO.setCapFlow(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CASH_FLOW_IN);
                prjPrdPaySchDVO.setIsSysDef(BaseConstant.IS_YESNO_YES);
                prjPrdPaySchDVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
                prjPrdPaySchDVO.setMdfTm(new Date());
                prjPrdPaySchDVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
                prjPrdPaySchDVO.setCrtTm(new Date());
                prjPrdPaySchDVO.setPaySchId(Long.valueOf(paySchId));
                feeList.add(prjPrdPaySchDVO);
            }
        }
        return feeList;
    }

    /**
     * 显示汽车金融提前结清详情页面
     */
    @RequestMapping(value = "/showCarPreSettlePage.do", method = {RequestMethod.GET})
    public ModelAndView showCarPreSettlePage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "showCarPreSettlePage", "显示提前结清详情页面.", CurrentThreadContext.getCurrentUserName());
        String paySchId = request.getParameter("paySchId");//支付表ID
        //String payPd =  request.getParameter("payPd");//提前结清时结清期数
        PrjBscInfoVO prj = null;
        PrjPrdPaySchMVO pay = null;
        CstBscInfoVO cst = null;
        ListPageVO<PrjPrdPrpsFeeDetailVO> listPage = null;
        ListPageVO<PrjPrdPaySchDVO> feeListPage = null;
        PrjPrdDtlVO dtl = null;
        Integer payPd = null;
        //Integer actPayPd = null;//实际换到的期数
        try {
            if (StringUtils.isNotBlank(paySchId)) {
                PrjPrdPaySchMVO paySchMVO = this.prjPrdPaySchMService.getPrjPrdPaySettPayPd(Long.valueOf(paySchId), PrjPrdPaySchMConstant.PRJ_PRD_Pay_SCH_M_PRE, new Date());
                if (null != paySchMVO) {
                    payPd = paySchMVO.getStartLsPd();
                } else {
                    PrjPrdPaySchMVO schMVO = this.prjPrdPaySchMService.selectById(Long.valueOf(paySchId));
                    payPd = schMVO.getLsPd();
                }
                /*PrjPrdDtlQueryCondition qc = new PrjPrdDtlQueryCondition();
                qc.setPaySchId(Long.valueOf(paySchId));
                List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(qc);
                if (CollectionUtils.isNotEmpty(dtlList)) {
                    dtl = dtlList.get(0);
                }*/
                pay = this.prjPrdPaySchMService.searchCarPreSettleData(Long.valueOf(paySchId), new Date(), Integer.valueOf(payPd));
                dtl = pay.getDtlVO();
                if (dtl == null) {
                    PrjPrdDtlQueryCondition qc = new PrjPrdDtlQueryCondition();
                    qc.setPaySchId(pay.getWsPaySchId());
                    List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(qc);
                    if (CollectionUtils.isNotEmpty(dtlList)) {
                        dtl = dtlList.get(0);
                    }
                }
                if (null != pay) {
                    //cst = this.cstBscInfoService.selectDetailById(pay.getCstId());
                    prj = this.prjBscInfoService.selectById(pay.getPrjId());
                }
            }
            if (CollectionUtils.isNotEmpty(pay.getPrjPrdPayDetailList())) {
                List<PrjPrdPrpsFeeDetailVO> feeList = pay.getPrjPrdPayDetailList();
                listPage = new ListPageVO<>(feeList, feeList.size());
                pay.setPrjQuatPrpsPaySchPage(listPage);
            }
            if (CollectionUtils.isNotEmpty(pay.getFeeDetailList())) {
                List<PrjPrdPaySchDVO> list = new ArrayList<PrjPrdPaySchDVO>();
                for (PrjPrdPaySchDVO prjPrdPaySchDVO : pay.getFeeDetailList()) {
                    if (prjPrdPaySchDVO.getFeeClsCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_PRPS) && !(prjPrdPaySchDVO.getCntWayCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_CONT))) {
                        list.add(prjPrdPaySchDVO);
                    }
                }
                //首期款合计项
                PrjPrdPaySchDVO tatal = new PrjPrdPaySchDVO();
                tatal.setFeeTypCdNm("首期款合计");
                tatal.setFeeAmt(pay.getFirstPayAmt());
                tatal.setPaidUpAmt(pay.getTotalFirstPayAmt().longValue());
                list.add(tatal);
                feeListPage = new ListPageVO<PrjPrdPaySchDVO>(list, list.size());
                pay.setFeeDetailListPage(feeListPage);
            }
            if (CollectionUtils.isNotEmpty(pay.getSubFeeAmtTotalList())) {
                for (PrjPrdPaySchDVO paySchDVO : pay.getSubFeeAmtTotalList()) {
                    paySchDVO.setFeeAmt(DecimalUtils.convertFenToYuan(paySchDVO.getFeeAmt().longValue()));
                }
            }
            ListPageVO<PrjPrdPaySchDVO> settListPage = new ListPageVO<PrjPrdPaySchDVO>(pay.getSettFeeAmtList(), pay.getSettFeeAmtList().size());
            List<SysDictionaryVO> settFeeTypCdListJSON = this.prjPrdPaySchMService.getSettFeeTypList();
            ModelAndView view = new ModelAndView("project/prjprdquatprps/prjPrdPaySchMCarPreSettleDetailPage");
            view.addObject("pay", pay);
            //view.addObject("cst", cst);
            view.addObject("prj", prj);
            view.addObject("dtl", dtl);
            view.addObject("settFeeTypCdListJSON", JSON.toJSONString(settFeeTypCdListJSON));
            view.addObject("subFeeAmtTotalList", JSON.toJSONString(pay.getSubFeeAmtTotalList()));
            view.addObject("listPage", JSON.toJSONString(listPage));
            view.addObject("feeListPage", JSON.toJSONString(feeListPage));
            view.addObject("paySchId", paySchId);
            view.addObject("settFeeList", JSON.toJSONString(settListPage));
            view.addObject("model", "preview");// 代表结清申请预览
            return view;
        } catch (BaseException ex) {
            BaseLogUtils.error(logger, "showPreSettlePage", "显示提前结清详情页面查询失败.DATA:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
            throw ex;
        } catch (Exception ex) {
            BaseLogUtils.error(logger, "showPreSettlePage", "显示提前结清详情页面查询失败.DATA:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
            throw ex;
        }
    }

    /**
     * 发起乘用车提前结清流程
     */
    @RequestMapping(value = "/applyCarPreSett.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object applyCarPreSett(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
        PrjPrdPaySchMVO pay = null;//获取参数
        String prjPrdSchId = request.getParameter("paySchId");
        String totalSettAmt = request.getParameter("totalSettAmt");//最终结清款
        String payPd = request.getParameter("payPd");//结清期次
        DataResultVO resultVO = null;
        List<PrjPrdPaySchDVO> entityList = null;
        try {
            pay = new PrjPrdPaySchMVO();
            if (StringUtils.isNotBlank(prjPrdSchId)) {
                pay.setId(Long.valueOf(prjPrdSchId));
            }
            entityList = this.getRequestParamForSettFeeList(request);
            if (CollectionUtils.isNotEmpty(entityList)) {
                pay.setFeeDetailList(entityList);
            }
            if (StringUtils.isNotBlank(totalSettAmt)) {
                pay.setStlAmt(DecimalUtils.convertYuanToFen(Double.valueOf(totalSettAmt)));
            }
            if (StringUtils.isNotBlank(payPd)) {
                pay.setStlPd(Integer.valueOf(payPd));
            }
            pay.setBuOrgCd(PrjBscInfoConstant.CODE_BU_ORG_CD_QCJR);
            resultVO = this.prjPrdPaySchMService.addFileAndPreNormalSett(pay);

            BaseLogUtils.info(logger, "applyCarPreSett", "发起提前结清流程成功," + ".DATA:" + JSONObject.toJSONString(pay), CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            resultVO = new DataResultVO();
            resultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            resultVO.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.info(logger, "applyCarPreSett", "发起提前结清流程失败.DATA:" + JSONObject.toJSONString(pay) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
            return resultVO;
        } catch (Exception ex) {
            resultVO = new DataResultVO();
            resultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            resultVO.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.error(logger, "applyCarPreSett", "发起提前结清流程失败,系统错误.DATA:" + JSONObject.toJSONString(pay) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
            return resultVO;
        }
        return resultVO;
    }

    private List<PrjPrdPaySchDVO> getRequestParamForCarSettFeeList(HttpServletRequest request) throws BaseException {
        List<PrjPrdPaySchDVO> feeList = new ArrayList<PrjPrdPaySchDVO>();
        String settFeeList = request.getParameter("settFeeList");//新添加的结清费用项
        String paySchId = request.getParameter("paySchId");//支付表ID
        String settFlag = request.getParameter("settFlag");
        String breachAmt = request.getParameter("breachAmt");//违约金
        if (StringUtils.isNotBlank(settFeeList)) {
            feeList = JSON.parseArray(settFeeList, PrjPrdPaySchDVO.class);
            for (PrjPrdPaySchDVO prjPrdPaySchDVO : feeList) {
                if (StringUtils.isNotBlank(paySchId)) {
                    prjPrdPaySchDVO.setPaySchId(Long.valueOf(paySchId));
                    if (null == prjPrdPaySchDVO.getFeeAmt()) {
                        throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "费用项金额不能为空!");
                    }
                    if (null == prjPrdPaySchDVO.getFeeTypCd() || StringUtils.isBlank(prjPrdPaySchDVO.getFeeTypCd())) {
                        throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "费用项类型不能为空!");
                    }
                }
                if (StringUtils.isBlank(prjPrdPaySchDVO.getFeeClsCd())) {
                    prjPrdPaySchDVO.setFeeClsCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_SETT);
                }
                prjPrdPaySchDVO.setFeeAmt(DecimalUtils.convertYuanToFen(prjPrdPaySchDVO.getFeeAmt()).doubleValue());
                /*if (null == prjPrdPaySchDVO.getArAmt()) {
                    prjPrdPaySchDVO.setArAmt(prjPrdPaySchDVO.getFeeAmt().longValue());
                }*/

                //费用金额不对修改
                prjPrdPaySchDVO.setArAmt(prjPrdPaySchDVO.getFeeAmt().longValue());

                prjPrdPaySchDVO.setPayPd(PrjQuatPrpsConstant.CODE_PRJ_PRD_PAY_PD);
                prjPrdPaySchDVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
                prjPrdPaySchDVO.setMdfTm(new Date());
                prjPrdPaySchDVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
                prjPrdPaySchDVO.setCrtTm(new Date());
                prjPrdPaySchDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_OTH);
                prjPrdPaySchDVO.setIsDel(BaseConstant.IS_YESNO_NO);
            }
            //提前结清加入默认的违约金的值
            if (StringUtils.isNotBlank(settFlag) && settFlag.equals(PrjPrdPaySchMConstant.PRJ_PRD_Pay_SCH_M_PRE) && StringUtils.isNotBlank(breachAmt)) {
                //违约金
                PrjPrdPaySchDVO prjPrdPaySchDVO = new PrjPrdPaySchDVO();
                prjPrdPaySchDVO.setFeeAmt(DecimalUtils.convertYuanToFen(Double.valueOf(breachAmt)).doubleValue());
                prjPrdPaySchDVO.setArAmt(DecimalUtils.convertYuanToFen(Double.valueOf(breachAmt)));
                prjPrdPaySchDVO.setIsFixedAmt(BaseConstant.IS_YESNO_YES);
                prjPrdPaySchDVO.setFeeClsCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_SETT);
                prjPrdPaySchDVO.setPayPd(PrjQuatPrpsConstant.CODE_PRJ_PRD_PAY_PD);
                prjPrdPaySchDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_OTH);
                prjPrdPaySchDVO.setIsDel(BaseConstant.IS_YESNO_NO);
                prjPrdPaySchDVO.setFeeTypCd(PrjQuatPrpsFeeConstant.FEE_TYP_CD_103);
                prjPrdPaySchDVO.setCapFlow(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CASH_FLOW_IN);
                prjPrdPaySchDVO.setIsSysDef(BaseConstant.IS_YESNO_YES);
                prjPrdPaySchDVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
                prjPrdPaySchDVO.setMdfTm(new Date());
                prjPrdPaySchDVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
                prjPrdPaySchDVO.setCrtTm(new Date());
                prjPrdPaySchDVO.setPaySchId(Long.valueOf(paySchId));
                feeList.add(prjPrdPaySchDVO);
            }

        }
        return feeList;
    }


    /**
     * 显示分解之前的结清数据
     */
    @RequestMapping(value = "/searchBeforeSplitSettleData.do", method = {RequestMethod.GET})
    public ModelAndView searchbeforeSplitSettleData(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "searchBeforeSplitSettleData", "显示提前结清流程中详情页面.", CurrentThreadContext.getCurrentUserName());
        String paySchId = request.getParameter("paySchId");//支付表ID
        String isDetail_bk = request.getParameter("isDetail_bk");//标识是否详情_YAOXIURONG
        String showBk_oCIn = request.getParameter("showBk_oCIn");//加载我司收款账号维护页面
        String showBk_oCOut = request.getParameter("showBk_oCOut");//加载我司付款账号维护页面
        String editInto = request.getParameter("editInto");//我司付款_维护收款账号
        String editOut = request.getParameter("editOut");//我司付款_维护付款账号

        String openTheBillAdd = request.getParameter("optba");//标识是否需要开票新增列表页面_FUJINGRUN
        String openTheBillForFinance = request.getParameter("optbf");//标识是否显示财务开票列表页面_FUJINGRUN
        String openTheBillForDetail = request.getParameter("optbd");//是否显示开票详细列表页面_FUJINGRUN
        String procInstId = request.getParameter("processInstanceId");//流程实例ID_FUJINGRUN
        Integer payPd = 0;//提前结清时结清期数
        PrjBscInfoVO prj = null;
        PrjPrdPaySchMVO pay = null;
        CstBscInfoVO cst = null;
        ListPageVO<PrjPrdPrpsFeeDetailVO> listPage = null;
        ListPageVO<PrjPrdPaySchDVO> feeListPage = null;
        PrjPrdDtlVO dtl = null;
        Date applyDate = null;
        try {
            if (StringUtils.isNotBlank(paySchId)) {
                // 查找结清期数
                PrjPrdPaySchMVO schMVO = getSchMVO(procInstId, Long.valueOf(paySchId));
                payPd = schMVO.getStlPd();

                PrjStlMVO prjStlMVO = this.prjStlMService.selectByPaySchMId(Long.valueOf(paySchId), PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_CST);
                if (null == prjStlMVO) {
                    pay = this.prjPrdPaySchMService.searchSettleData(Long.valueOf(paySchId), null, payPd);
                } else {
                    pay = this.prjPrdPaySchMService.searchSettleDataForFlow(Long.valueOf(paySchId), null, payPd);
                }
                PrjPrdDtlQueryCondition qc = new PrjPrdDtlQueryCondition();
                qc.setPaySchId(pay.getWsPaySchId());
                List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(qc);
                if (CollectionUtils.isNotEmpty(dtlList)) {
                    dtl = dtlList.get(0);
                }
                if (null != pay) {
                    cst = this.cstBscInfoService.selectDetailById(pay.getCstId());
                    prj = this.prjBscInfoService.selectById(pay.getPrjId());
                }
                if (CollectionUtils.isNotEmpty(pay.getPrjPrdPayDetailList())) {
                    listPage = new ListPageVO<PrjPrdPrpsFeeDetailVO>(pay.getPrjPrdPayDetailList(), pay.getPrjPrdPayDetailList().size());
                    pay.setPrjQuatPrpsPaySchPage(listPage);
                }
                if (CollectionUtils.isNotEmpty(pay.getFeeDetailList())) {
                    List<PrjPrdPaySchDVO> list = new ArrayList<PrjPrdPaySchDVO>();
                    for (PrjPrdPaySchDVO prjPrdPaySchDVO : pay.getFeeDetailList()) {
                        if (prjPrdPaySchDVO.getFeeClsCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_PRPS)) {
                            list.add(prjPrdPaySchDVO);
                        }
                    }
                    //首期款合计项
                    PrjPrdPaySchDVO tatal = new PrjPrdPaySchDVO();
                    tatal.setFeeTypCdNm("首期款合计");
                    tatal.setFeeAmt(pay.getFirstPayAmt());
                    tatal.setPaidUpAmt(pay.getTotalFirstPayAmt().longValue());
                    list.add(tatal);
                    feeListPage = new ListPageVO<PrjPrdPaySchDVO>(list, list.size());
                    pay.setFeeDetailListPage(feeListPage);
                }
                if (CollectionUtils.isNotEmpty(pay.getSubFeeAmtTotalList())) {
                    for (PrjPrdPaySchDVO paySchDVO : pay.getSubFeeAmtTotalList()) {
                        paySchDVO.setFeeAmt(DecimalUtils.convertFenToYuan(paySchDVO.getFeeAmt().longValue()));
                    }
                }

            }
        } catch (BaseException ex) {
            BaseLogUtils.info(logger, "preSettleFlowPage", "结清流程中页面查询失败.DATA:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
        } catch (Exception ex) {
            BaseLogUtils.error(logger, "preSettleFlowPage", "结清流程中页面查询失败.DATA:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
        }
        List<SysDictionaryVO> settFeeTypCdListJSON = this.prjPrdPaySchMService.getSettFeeTypList();
        //费用类型
        ModelAndView view = new ModelAndView("project/prjprdquatprps/prjPrdPaySchMSplitSettlePage");
        view.addObject("pay", pay);
        view.addObject("cst", cst);
        view.addObject("prj", prj);
        view.addObject("dtl", dtl);
        view.addObject("showBk_oCIn", showBk_oCIn);
        view.addObject("isDetail_bk", isDetail_bk);
        view.addObject("showBk_oCOut", showBk_oCOut);
        view.addObject("editInto", editInto);
        view.addObject("editOut", editOut);
        view.addObject("subFeeAmtTotalList", JSON.toJSONString(pay.getSubFeeAmtTotalList()));
        view.addObject("listPage", JSON.toJSONString(listPage));
        view.addObject("feeListPage", JSON.toJSONString(feeListPage));
        view.addObject("paySchId", paySchId);
        view.addObject("settFeeTypCdListJSON", JSON.toJSONString(settFeeTypCdListJSON));
        view.addObject("optba", openTheBillAdd);
        view.addObject("optbf", openTheBillForFinance);
        view.addObject("optbd", openTheBillForDetail);
        view.addObject("procInstId", procInstId);
        return view;
    }

    /**
     * 显示分解之前的结清数据
     */
    @RequestMapping(value = "/searchBeforeSplitPreSettleData.do", method = {RequestMethod.GET})
    public ModelAndView searchbeforeSplitPreSettleData(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "newPreSettleFlowPage", "显示提前结清流程中详情页面.", CurrentThreadContext.getCurrentUserName());
        String paySchId = request.getParameter("paySchId");//支付表ID
        String isDetail_bk = request.getParameter("isDetail_bk");//标识是否详情_YAOXIURONG
        String showBk_oCIn = request.getParameter("showBk_oCIn");//加载我司收款账号维护页面
        String showBk_oCOut = request.getParameter("showBk_oCOut");//加载我司付款账号维护页面
        String editInto = request.getParameter("editInto");//我司付款_维护收款账号
        String editOut = request.getParameter("editOut");//我司付款_维护付款账号

        /*String showBk_oCIn = request.getParameter("showBk_oCIn");//标识是否加载账号页面_我司收款_YAOXIURONG
        String isDetail_bk = request.getParameter("isDetail_bk");//标识是否详情_YAOXIURONG
*/
        String openTheBillAdd = request.getParameter("optba");//标识是否需要开票新增列表页面_FUJINGRUN
        String openTheBillForFinance = request.getParameter("optbf");//标识是否显示财务开票列表页面_FUJINGRUN
        String openTheBillForDetail = request.getParameter("optbd");//是否显示开票详细列表页面_FUJINGRUN
        String procInstId = request.getParameter("processInstanceId");//流程实例ID_FUJINGRUN
        Integer payPd = 0;//提前结清时结清期数
        PrjBscInfoVO prj = null;
        PrjPrdPaySchMVO pay = null;
        CstBscInfoVO cst = null;
        ListPageVO<PrjPrdPrpsFeeDetailVO> listPage = null;
        ListPageVO<PrjPrdPaySchDVO> feeListPage = null;
        PrjPrdDtlVO dtl = null;
        Date applyDate = null;
        try {
            if (StringUtils.isNotBlank(paySchId)) {
                // 查找结清期数
                PrjPrdPaySchMVO schMVO = getSchMVO(procInstId, Long.valueOf(paySchId));
                payPd = schMVO.getStlPd();

                PrjStlMVO prjStlMVO = this.prjStlMService.selectByPaySchMId(Long.valueOf(paySchId), PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_CST);
                if (null == prjStlMVO) {
                    pay = this.prjPrdPaySchMService.searchPreSettleData(Long.valueOf(paySchId), null, payPd);
                } else {
                    pay = this.prjPrdPaySchMService.searchSettleDataForFlow(Long.valueOf(paySchId), null, payPd);
                }
                PrjPrdDtlQueryCondition qc = new PrjPrdDtlQueryCondition();
                qc.setPaySchId(pay.getWsPaySchId());
                List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(qc);
                if (CollectionUtils.isNotEmpty(dtlList)) {
                    dtl = dtlList.get(0);
                }
                if (null != pay) {
                    cst = this.cstBscInfoService.selectDetailById(pay.getCstId());
                    prj = this.prjBscInfoService.selectById(pay.getPrjId());
                }

                if (CollectionUtils.isNotEmpty(pay.getPrjPrdPayDetailList())) {
                    List<PrjPrdPrpsFeeDetailVO> feeList = null;
                    double totalRnt = 0d;//租金
                    double totalPrint = 0d;//本金
                    double totalInt = 0d;//利息
                    if (payPd != 0) {
                        //查询流程中临时状态的期数
                        Integer payPdFlow = null;
                        List<PrjPrdPaySchDVO> list = this.prjPrdPaySchDService.selectPaySchByDelStatusAndPaySchId(Long.valueOf(paySchId), PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                        if (CollectionUtils.isNotEmpty(list)) {
                            payPdFlow = list.get(0).getPayPd();
                            feeList = new ArrayList<PrjPrdPrpsFeeDetailVO>();
                            for (PrjPrdPrpsFeeDetailVO payDetail : pay.getPrjPrdPayDetailList()) {
                                if (payDetail.getPayPd().intValue() < Integer.valueOf(payPdFlow).intValue()) {
                                    totalRnt = DecimalUtils.add(totalRnt, payDetail.getRntAmt());
                                    totalPrint = DecimalUtils.add(totalPrint, payDetail.getPrinAmt());
                                    totalInt = DecimalUtils.add(totalInt, payDetail.getIntAmt());
                                    feeList.add(payDetail);
                                }
                                if (payDetail.getPayPd().intValue() == Integer.valueOf(payPdFlow).intValue()) {
                                    if (null != prjStlMVO) {
                                        payDetail.setRntAmt(prjStlMVO.getRmS01ArTotAmt());
                                        payDetail.setPrinAmt(prjStlMVO.getRmS03ArTotAmt());
                                        payDetail.setIntAmt(prjStlMVO.getRmS02ArTotAmt());
                                        payDetail.setRemPrinAmt(0d);
                                        payDetail.setIsDel(PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                                    } else {
                                        payDetail.setRntAmt(DecimalUtils.sub(pay.getTotalRntAmt(), totalRnt));
                                        payDetail.setPrinAmt(DecimalUtils.sub(pay.getTotalPrinAmt(), totalPrint));
                                        payDetail.setIntAmt(DecimalUtils.sub(pay.getTotalIntAmt(), totalInt));
                                        payDetail.setRemPrinAmt(0d);
                                        payDetail.setIsDel(PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                                    }
                                    feeList.add(payDetail);
                                }
                            }

                        } else {
                            //payPdFlow = payPd;
                            feeList = pay.getPrjPrdPayDetailList();
                        }

                    } else {
                        feeList = pay.getPrjPrdPayDetailList();
                    }
                    listPage = new ListPageVO<PrjPrdPrpsFeeDetailVO>(feeList, feeList.size());
                    pay.setPrjQuatPrpsPaySchPage(listPage);
                }

                if (CollectionUtils.isNotEmpty(pay.getFeeDetailList())) {
                    List<PrjPrdPaySchDVO> list = new ArrayList<PrjPrdPaySchDVO>();
                    for (PrjPrdPaySchDVO prjPrdPaySchDVO : pay.getFeeDetailList()) {
                        if (prjPrdPaySchDVO.getFeeClsCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_PRPS)) {
                            list.add(prjPrdPaySchDVO);
                        }
                    }
                    //首期款合计项
                    PrjPrdPaySchDVO tatal = new PrjPrdPaySchDVO();
                    tatal.setFeeTypCdNm("首期款合计");
                    tatal.setFeeAmt(pay.getFirstPayAmt());
                    tatal.setPaidUpAmt(pay.getTotalFirstPayAmt().longValue());
                    list.add(tatal);
                    feeListPage = new ListPageVO<PrjPrdPaySchDVO>(list, list.size());
                    pay.setFeeDetailListPage(feeListPage);
                }
                if (CollectionUtils.isNotEmpty(pay.getSubFeeAmtTotalList())) {
                    for (PrjPrdPaySchDVO paySchDVO : pay.getSubFeeAmtTotalList()) {
                        paySchDVO.setFeeAmt(DecimalUtils.convertFenToYuan(paySchDVO.getFeeAmt().longValue()));
                    }
                }

            }
        } catch (BaseException ex) {
            BaseLogUtils.info(logger, "preSettleFlowPage", "结清流程中页面查询失败.DATA:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
        } catch (Exception ex) {
            BaseLogUtils.error(logger, "preSettleFlowPage", "结清流程中页面查询失败.DATA:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
        }
        List<SysDictionaryVO> settFeeTypCdListJSON = this.prjPrdPaySchMService.getSettFeeTypList();
        //费用类型
        ModelAndView view = new ModelAndView("project/prjprdquatprps/prjPrdPaySchMPreSplitSettlePage");
        view.addObject("pay", pay);
        view.addObject("cst", cst);
        view.addObject("prj", prj);
        view.addObject("dtl", dtl);
        view.addObject("showBk_oCIn", showBk_oCIn);
        view.addObject("isDetail_bk", isDetail_bk);
        view.addObject("showBk_oCOut", showBk_oCOut);
        view.addObject("editInto", editInto);
        view.addObject("editOut", editOut);
        view.addObject("subFeeAmtTotalList", JSON.toJSONString(pay.getSubFeeAmtTotalList()));
        view.addObject("listPage", JSON.toJSONString(listPage));
        view.addObject("feeListPage", JSON.toJSONString(feeListPage));
        view.addObject("paySchId", paySchId);
        view.addObject("settFeeTypCdListJSON", JSON.toJSONString(settFeeTypCdListJSON));
        view.addObject("optba", openTheBillAdd);
        view.addObject("optbf", openTheBillForFinance);
        view.addObject("optbd", openTheBillForDetail);
        view.addObject("procInstId", procInstId);
        return view;
    }


    /**
     * 显示分解之前的结清数据
     */
    @RequestMapping(value = "/searchBeforeSplitCarPreSettleData.do", method = {RequestMethod.GET})
    public ModelAndView searchBeforeSplitCarPreSettleData(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "newPreSettleFlowPage", "显示提前结清流程中详情页面.", CurrentThreadContext.getCurrentUserName());
        String paySchId = request.getParameter("paySchId");//支付表ID
        String isDetail_bk = request.getParameter("isDetail_bk");//标识是否详情_YAOXIURONG
        String showBk_oCIn = request.getParameter("showBk_oCIn");//加载我司收款账号维护页面
        String showBk_oCOut = request.getParameter("showBk_oCOut");//加载我司付款账号维护页面
        String editInto = request.getParameter("editInto");//我司付款_维护收款账号
        String editOut = request.getParameter("editOut");//我司付款_维护付款账号

        String openTheBillAdd = request.getParameter("optba");//标识是否需要开票新增列表页面_FUJINGRUN
        String openTheBillForFinance = request.getParameter("optbf");//标识是否显示财务开票列表页面_FUJINGRUN
        String openTheBillForDetail = request.getParameter("optbd");//是否显示开票详细列表页面_FUJINGRUN
        String procInstId = request.getParameter("processInstanceId");//流程实例ID_FUJINGRUN
        Integer payPd = 0;//提前结清时结清期数
        PrjBscInfoVO prj = null;
        PrjPrdPaySchMVO pay = null;
        CstBscInfoVO cst = null;
        ListPageVO<PrjPrdPrpsFeeDetailVO> listPage = null;
        ListPageVO<PrjPrdPaySchDVO> feeListPage = null;
        PrjPrdDtlVO dtl = null;
        Date applyDate = null;
        try {
            if (StringUtils.isNotBlank(paySchId)) {
                // 查找结清期数
                PrjPrdPaySchMVO schMVO = getSchMVO(procInstId, Long.valueOf(paySchId));
                payPd = schMVO.getStlPd();

                PrjStlMVO prjStlMVO = this.prjStlMService.selectByPaySchMId(Long.valueOf(paySchId), PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_CST);
                if (null == prjStlMVO) {
                    pay = this.prjPrdPaySchMService.searchCarPreSettleData(Long.valueOf(paySchId), null, Integer.valueOf(payPd));
                } else {
                    pay = this.prjPrdPaySchMService.searchSettleDataForFlow(Long.valueOf(paySchId), null, Integer.valueOf(payPd));
                }
                PrjPrdDtlQueryCondition qc = new PrjPrdDtlQueryCondition();
                qc.setPaySchId(Long.valueOf(paySchId));
                List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(qc);
                if (CollectionUtils.isNotEmpty(dtlList)) {
                    dtl = dtlList.get(0);
                }
                if (null != pay) {
                    cst = this.cstBscInfoService.selectDetailById(pay.getCstId());
                    prj = this.prjBscInfoService.selectById(pay.getPrjId());
                }

                if (CollectionUtils.isNotEmpty(pay.getPrjPrdPayDetailList())) {
                    List<PrjPrdPrpsFeeDetailVO> feeList = null;
                    double totalRnt = 0d;//租金
                    double totalPrint = 0d;//本金
                    double totalInt = 0d;//利息
                    if (payPd != 0) {
                        //查询流程中临时状态的期数
                        Integer payPdFlow = null;
                        List<PrjPrdPaySchDVO> list = this.prjPrdPaySchDService.selectPaySchByDelStatusAndPaySchId(Long.valueOf(paySchId), PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                        if (CollectionUtils.isNotEmpty(list)) {
                            payPdFlow = list.get(0).getPayPd();
                            feeList = new ArrayList<PrjPrdPrpsFeeDetailVO>();
                            for (PrjPrdPrpsFeeDetailVO payDetail : pay.getPrjPrdPayDetailList()) {
                                if (payDetail.getPayPd().intValue() < Integer.valueOf(payPdFlow).intValue()) {
                                    totalRnt = DecimalUtils.add(totalRnt, payDetail.getRntAmt());
                                    totalPrint = DecimalUtils.add(totalPrint, payDetail.getPrinAmt());
                                    totalInt = DecimalUtils.add(totalInt, payDetail.getIntAmt());
                                    feeList.add(payDetail);
                                }
                                if (payDetail.getPayPd().intValue() == Integer.valueOf(payPdFlow).intValue()) {
                                    if (null != prjStlMVO) {
                                        payDetail.setRntAmt(prjStlMVO.getRmS01ArTotAmt());
                                        payDetail.setPrinAmt(prjStlMVO.getRmS03ArTotAmt());
                                        payDetail.setIntAmt(prjStlMVO.getRmS02ArTotAmt());
                                        payDetail.setRemPrinAmt(0d);
                                        payDetail.setIsDel(PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                                    } else {
                                        payDetail.setRntAmt(DecimalUtils.sub(pay.getTotalRntAmt(), totalRnt));
                                        payDetail.setPrinAmt(DecimalUtils.sub(pay.getTotalPrinAmt(), totalPrint));
                                        payDetail.setIntAmt(DecimalUtils.sub(pay.getTotalIntAmt(), totalInt));
                                        payDetail.setRemPrinAmt(0d);
                                        payDetail.setIsDel(PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                                    }
                                    feeList.add(payDetail);
                                }
                            }

                        } else {
                            //payPdFlow = payPd;
                            feeList = pay.getPrjPrdPayDetailList();
                        }

                    } else {
                        feeList = pay.getPrjPrdPayDetailList();
                    }
                    listPage = new ListPageVO<PrjPrdPrpsFeeDetailVO>(feeList, feeList.size());
                    pay.setPrjQuatPrpsPaySchPage(listPage);
                }

                if (CollectionUtils.isNotEmpty(pay.getFeeDetailList())) {
                    List<PrjPrdPaySchDVO> list = new ArrayList<PrjPrdPaySchDVO>();
                    for (PrjPrdPaySchDVO prjPrdPaySchDVO : pay.getFeeDetailList()) {
                        if (prjPrdPaySchDVO.getFeeClsCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_PRPS)) {
                            list.add(prjPrdPaySchDVO);
                        }
                    }
                    //首期款合计项
                    PrjPrdPaySchDVO tatal = new PrjPrdPaySchDVO();
                    tatal.setFeeTypCdNm("首期款合计");
                    tatal.setFeeAmt(pay.getFirstPayAmt());
                    tatal.setPaidUpAmt(pay.getTotalFirstPayAmt().longValue());
                    list.add(tatal);
                    feeListPage = new ListPageVO<PrjPrdPaySchDVO>(list, list.size());
                    pay.setFeeDetailListPage(feeListPage);
                }
                if (CollectionUtils.isNotEmpty(pay.getSubFeeAmtTotalList())) {
                    for (PrjPrdPaySchDVO paySchDVO : pay.getSubFeeAmtTotalList()) {
                        paySchDVO.setFeeAmt(DecimalUtils.convertFenToYuan(paySchDVO.getFeeAmt().longValue()));
                    }
                }

            }
        } catch (BaseException ex) {
            BaseLogUtils.info(logger, "preSettleFlowPage", "结清流程中页面查询失败.DATA:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
        } catch (Exception ex) {
            BaseLogUtils.error(logger, "preSettleFlowPage", "结清流程中页面查询失败.DATA:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
        }
        List<SysDictionaryVO> settFeeTypCdListJSON = this.prjPrdPaySchMService.getSettFeeTypList();
        //费用类型
        ModelAndView view = new ModelAndView("project/prjprdquatprps/prjPrdPaySchMCarPreSplitSettleFlowPage");
        view.addObject("pay", pay);
        view.addObject("cst", cst);
        view.addObject("prj", prj);
        view.addObject("dtl", dtl);
        view.addObject("showBk_oCIn", showBk_oCIn);
        view.addObject("isDetail_bk", isDetail_bk);
        view.addObject("showBk_oCOut", showBk_oCOut);
        view.addObject("editInto", editInto);
        view.addObject("editOut", editOut);
        view.addObject("subFeeAmtTotalList", JSON.toJSONString(pay.getSubFeeAmtTotalList()));
        view.addObject("listPage", JSON.toJSONString(listPage));
        view.addObject("feeListPage", JSON.toJSONString(feeListPage));
        view.addObject("paySchId", paySchId);
        view.addObject("settFeeTypCdListJSON", JSON.toJSONString(settFeeTypCdListJSON));
        view.addObject("optba", openTheBillAdd);
        view.addObject("optbf", openTheBillForFinance);
        view.addObject("optbd", openTheBillForDetail);
        view.addObject("procInstId", procInstId);
        return view;
    }


    /**
     * 发起乘用车正常结清流程
     */
    @RequestMapping(value = "/applyCarNormalSett.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object applyCarNormalSett(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
        PrjPrdPaySchMVO pay = null;//获取参数
        String prjPrdSchId = request.getParameter("paySchId");
        String totalSettAmt = request.getParameter("totalSettAmt");//最终结清款
        String payPd = request.getParameter("payPd");//结清期数
        DataResultVO resultVO = null;
        List<PrjPrdPaySchDVO> entityList = null;//获取参数
        try {

            pay = new PrjPrdPaySchMVO();
            if (StringUtils.isNotBlank(prjPrdSchId)) {
                pay.setId(Long.valueOf(prjPrdSchId));
            }
            if (StringUtils.isNotBlank(payPd)) {
                pay.setStlPd(Integer.valueOf(payPd));
            }
            List<SysUlFilesRecVO> fileList = new ArrayList<SysUlFilesRecVO>();

            //发起结清剔除    结清费用项:settFeeList
            request.removeAttribute("settFeeList");

            entityList = this.getRequestParamForSettFeeList(request);//获取参数

            if (CollectionUtils.isNotEmpty(entityList)) {
                pay.setFeeDetailList(entityList);
            }
            if (StringUtils.isNotBlank(totalSettAmt)) {
                pay.setStlAmt(DecimalUtils.convertYuanToFen(Double.valueOf(totalSettAmt)));
            }
            resultVO = this.prjPrdPaySchMService.addFileAndApplyCarNormalSett(pay);

            BaseLogUtils.info(logger, "applyNormalSett", "发起正常结清流程成功," + ".DATA:" + JSONObject.toJSONString(pay), CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            resultVO = new DataResultVO();
            resultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            resultVO.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "applyNormalSett", "发起正常结清流程失败.DATA:" + JSONObject.toJSONString(pay) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(),ex);
            return resultVO;
        } catch (Exception ex) {
            resultVO = new DataResultVO();
            resultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            resultVO.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.error(logger, "applyNormalSett", "发起正常结清流程失败,系统错误.DATA:" + JSONObject.toJSONString(pay) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(),ex);
            return resultVO;
        }
        return resultVO;
    }

    /**
     * 结清添加费用项页面
     */
    @RequestMapping(value = "/settleCarNormalAddFeePage.do", method = {RequestMethod.GET})
    public ModelAndView settleCarNormalAddFeePage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toListPage", "加载PrjPrdPaySchM列表页面.", CurrentThreadContext.getCurrentUserName());
        String paySchId = request.getParameter("paySchId");//支付表ID
        String isDetail = request.getParameter("isDetail");
        String taskDefKey = request.getParameter("taskDefKey");
        PrjBscInfoVO prj = null;
        PrjPrdPaySchMVO pay = null;
        CstBscInfoVO cst = null;
        ListPageVO<PrjPrdPrpsFeeDetailVO> listPage = null;
        ListPageVO<PrjPrdPaySchDVO> feeListPage = null;
        PrjPrdDtlVO dtl = null;
        Integer payPd = null;
        Date applyDate = null;
        try {
            if (StringUtils.isNotBlank(paySchId)) {

                PrjStlMVO stlMVO = this.prjStlMService.selectByPaySchMId(Long.valueOf(paySchId), PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_CST);

                // 查找结清期数
                PrjPrdPaySchMVO schMVO = getSchMVO("", Long.valueOf(paySchId));
                payPd = schMVO.getStlPd();

                pay = this.prjPrdPaySchMService.searchCarNormalSettleData(Long.valueOf(paySchId), null, payPd);
                if (null != pay) {
                    cst = this.cstBscInfoService.selectDetailById(pay.getCstId());
                    prj = this.prjBscInfoService.selectById(pay.getPrjId());
                    // 申请时间
                    applyDate = pay.getApplyDt();
                    if (null != stlMVO && null != applyDate && null != stlMVO.getStlStDt()
                            && org.apache.commons.lang3.time.DateUtils.isSameDay(applyDate, stlMVO.getStlStDt())) {
                        if (null != stlMVO.getRmS03ArTotAmt()) {
                            pay.setLastPrintAmt(stlMVO.getRmS03ArTotAmt() - (null == stlMVO.getStlOverdueS03Amt() ? 0 : stlMVO.getStlOverdueS03Amt()));
                        }
                        if (null != stlMVO.getRmS02ArTotAmt()) {
                            pay.setLastIntAmt(stlMVO.getRmS02ArTotAmt() - (null == stlMVO.getStlOverdueS02Amt() ? 0 : stlMVO.getStlOverdueS02Amt()));
                        }
                        if (null != stlMVO.getRmS01ArTotAmt()) {
                            pay.setLastRntAmt(stlMVO.getRmS01ArTotAmt() - (null == stlMVO.getStlOverdueAmt() ? 0 : stlMVO.getStlOverdueAmt()));
                        }
                        if (null != stlMVO.getStlPenaltyAmt()) {
                            pay.setPenaltyAmt(stlMVO.getStlPenaltyAmt());
                        }
                        if (null != stlMVO.getStlOverdueAmt()) {
                            pay.setOverdueAmt(stlMVO.getStlOverdueAmt());
                        }
                        if (null != stlMVO.getStlAmt()) {
                            pay.setStlAmt(stlMVO.getStlAmt().longValue());
                            pay.setFinalPayAmt(stlMVO.getStlAmt());
                            pay.setTotalSettAmt(stlMVO.getStlAmt());
                        }
                    }
                }
                PrjPrdDtlQueryCondition qc = new PrjPrdDtlQueryCondition();
                qc.setPaySchId(Long.valueOf(paySchId));
                List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(qc);
                if (CollectionUtils.isNotEmpty(dtlList)) {
                    dtl = dtlList.get(0);
                }
            }
            if (CollectionUtils.isNotEmpty(pay.getPrjPrdPayDetailList())) {
                listPage = new ListPageVO<PrjPrdPrpsFeeDetailVO>(pay.getPrjPrdPayDetailList(), pay.getPrjPrdPayDetailList().size());
                pay.setPrjQuatPrpsPaySchPage(listPage);
            }
            if (CollectionUtils.isNotEmpty(pay.getFeeDetailList())) {
                List<PrjPrdPaySchDVO> list = new ArrayList<PrjPrdPaySchDVO>();
                for (PrjPrdPaySchDVO prjPrdPaySchDVO : pay.getFeeDetailList()) {
                    if (prjPrdPaySchDVO.getFeeClsCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_PRPS)) {
                        list.add(prjPrdPaySchDVO);
                    }
                }
                //首期款合计项
                PrjPrdPaySchDVO tatal = new PrjPrdPaySchDVO();
                tatal.setFeeTypCdNm("首期款合计");
                tatal.setFeeAmt(pay.getFirstPayAmt());
                tatal.setPaidUpAmt(pay.getTotalFirstPayAmt().longValue());
                list.add(tatal);
                feeListPage = new ListPageVO<PrjPrdPaySchDVO>(list, list.size());
                pay.setFeeDetailListPage(feeListPage);
            }
            if (CollectionUtils.isNotEmpty(pay.getSubFeeAmtTotalList())) {
                for (PrjPrdPaySchDVO paySchDVO : pay.getSubFeeAmtTotalList()) {
                    paySchDVO.setFeeAmt(DecimalUtils.convertFenToYuan(paySchDVO.getFeeAmt().longValue()));
                }
            }
            //费用类型
            List<SysDictionaryVO> settFeeTypCdListJSON = this.prjPrdPaySchMService.getSettFeeTypList();
            ModelAndView view = new ModelAndView("project/prjprdquatprps/prjPrdPaySchMCarNormalSettleAddFeePage");
            view.addObject("settFeeTypCdListJSON", JSON.toJSONString(settFeeTypCdListJSON));
            view.addObject("settleWay", "正常结清");
            view.addObject("pay", pay);
            view.addObject("cst", cst);
            view.addObject("prj", prj);
            view.addObject("listPage", JSON.toJSONString(listPage));
            view.addObject("feeListPage", JSON.toJSONString(feeListPage));
            view.addObject("subFeeAmtTotalList", JSON.toJSONString(pay.getSubFeeAmtTotalList()));
            view.addObject("paySchId", paySchId);
            view.addObject("dtl", dtl);
            view.addObject("isDetail", isDetail);
            view.addObject("taskDefKey", taskDefKey);
            view.addObject("wsPaySchId", pay.getWsPaySchId());
            view.addObject("fileAuth", request.getParameter("fileAuth"));
            return view;
        } catch (BaseException ex) {
            BaseLogUtils.info(logger, "settleAddFeePage", "结清添加费用项页面查询失败.DATA:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
            throw ex;
        } catch (Exception ex) {
            BaseLogUtils.error(logger, "settleAddFeePage", "结清添加费用项页面查询失败.DATA:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
            throw ex;
        }
    }

    /**
     * 正常结清流程中查看页面
     */
    @RequestMapping(value = "/settleCarNormalFlowPage.do", method = {RequestMethod.GET})
    public ModelAndView settleCarNormalFlowPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "settleFlowPage", "加载正常结清流程中查看页面.", CurrentThreadContext.getCurrentUserName());
        String paySchId = request.getParameter("paySchId");//支付表ID
        String isDetail_bk = request.getParameter("isDetail_bk");//标识是否详情_YAOXIURONG
        String showBk_oCIn = request.getParameter("showBk_oCIn");//加载我司收款账号维护页面
        String showBk_oCOut = request.getParameter("showBk_oCOut");//加载我司付款账号维护页面
        String editInto = request.getParameter("editInto");//我司付款_维护收款账号
        String editOut = request.getParameter("editOut");//我司付款_维护付款账号
        String confirm = request.getParameter("confirm");
        String openTheBillAdd = request.getParameter("optba");//标识是否需要开票新增列表页面_FUJINGRUN
        String openTheBillForFinance = request.getParameter("optbf");//标识是否显示财务开票列表页面_FUJINGRUN
        String openTheBillForDetail = request.getParameter("optbd");//是否显示开票详细列表页面_FUJINGRUN
        String procInstId = request.getParameter("processInstanceId");//流程实例ID_FUJINGRUN
        PrjBscInfoVO prj = null;
        PrjPrdPaySchMVO pay = null;
        CstBscInfoVO cst = null;
        ListPageVO<PrjPrdPrpsFeeDetailVO> listPage = null;
        ListPageVO<PrjPrdPaySchDVO> feeListPage = null;
        PrjPrdDtlVO dtl = null;
        Integer payPd = null;
        Date applyDate = null;
        try {
            if (StringUtils.isNotBlank(paySchId)) {
                PrjStlMVO stlMVO = this.prjStlMService.selectByPaySchMId(Long.valueOf(paySchId), PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_CST);

                // 查找结清期数
                PrjPrdPaySchMVO schMVO = getSchMVO(procInstId, Long.valueOf(paySchId));
                payPd = schMVO.getStlPd();

                pay = this.prjPrdPaySchMService.searchCarNormalSettleData(Long.valueOf(paySchId), null, payPd);
                if (null != pay) {
                    cst = this.cstBscInfoService.selectDetailById(pay.getCstId());
                    prj = this.prjBscInfoService.selectById(pay.getPrjId());
                    PrjPrdDtlQueryCondition qc = new PrjPrdDtlQueryCondition();
                    qc.setPaySchId(Long.valueOf(paySchId));
                    List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(qc);
                    if (CollectionUtils.isNotEmpty(dtlList)) {
                        dtl = dtlList.get(0);
                    }
                    // 申请时间
                    applyDate = pay.getApplyDt();
                    if (null != stlMVO && null != applyDate && null != stlMVO.getStlStDt()
                            && org.apache.commons.lang3.time.DateUtils.isSameDay(applyDate, stlMVO.getStlStDt())) {
                        if (null != stlMVO.getRmS03ArTotAmt()) {
                            pay.setLastPrintAmt(stlMVO.getRmS03ArTotAmt() - (null == stlMVO.getStlOverdueS03Amt() ? 0 : stlMVO.getStlOverdueS03Amt()));
                        }
                        if (null != stlMVO.getRmS02ArTotAmt()) {
                            pay.setLastIntAmt(stlMVO.getRmS02ArTotAmt() - (null == stlMVO.getStlOverdueS02Amt() ? 0 : stlMVO.getStlOverdueS02Amt()));
                        }
                        if (null != stlMVO.getRmS01ArTotAmt()) {
                            pay.setLastRntAmt(stlMVO.getRmS01ArTotAmt() - (null == stlMVO.getStlOverdueAmt() ? 0 : stlMVO.getStlOverdueAmt()));
                        }
                        if (null != stlMVO.getStlPenaltyAmt()) {
                            pay.setPenaltyAmt(stlMVO.getStlPenaltyAmt());
                        }
                        if (null != stlMVO.getStlOverdueAmt()) {
                            pay.setOverdueAmt(stlMVO.getStlOverdueAmt());
                        }
                        if (null != stlMVO.getStlAmt()) {
                            pay.setStlAmt(stlMVO.getStlAmt().longValue());
                            pay.setFinalPayAmt(stlMVO.getStlAmt());
                            pay.setTotalSettAmt(stlMVO.getStlAmt());
                        }
                    }
                }

                if (CollectionUtils.isNotEmpty(pay.getPrjPrdPayDetailList())) {
                    listPage = new ListPageVO<PrjPrdPrpsFeeDetailVO>(pay.getPrjPrdPayDetailList(), pay.getPrjPrdPayDetailList().size());
                    pay.setPrjQuatPrpsPaySchPage(listPage);
                }
                if (CollectionUtils.isNotEmpty(pay.getFeeDetailList())) {
                    List<PrjPrdPaySchDVO> list = new ArrayList<PrjPrdPaySchDVO>();
                    for (PrjPrdPaySchDVO prjPrdPaySchDVO : pay.getFeeDetailList()) {
                        if (prjPrdPaySchDVO.getFeeClsCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_PRPS)) {
                            list.add(prjPrdPaySchDVO);
                        }
                    }
                    //首期款合计项
                    PrjPrdPaySchDVO tatal = new PrjPrdPaySchDVO();
                    tatal.setFeeTypCdNm("首期款合计");
                    tatal.setFeeAmt(pay.getFirstPayAmt());
                    tatal.setPaidUpAmt(pay.getTotalFirstPayAmt().longValue());
                    list.add(tatal);
                    feeListPage = new ListPageVO<PrjPrdPaySchDVO>(list, list.size());
                    pay.setFeeDetailListPage(feeListPage);
                }
                if (CollectionUtils.isNotEmpty(pay.getSubFeeAmtTotalList())) {
                    for (PrjPrdPaySchDVO paySchDVO : pay.getSubFeeAmtTotalList()) {
                        paySchDVO.setFeeAmt(DecimalUtils.convertFenToYuan(paySchDVO.getFeeAmt().longValue()));
                    }
                }

            }
        } catch (BaseException ex) {
            BaseLogUtils.info(logger, "settleFlowPage", "正常结清流程中查看页面查询失败.DATA:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
        } catch (Exception ex) {
            BaseLogUtils.error(logger, "settleFlowPage", "正常结清流程中查看页面查询失败.DATA:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
        }
        //费用类型
        List<SysDictionaryVO> settFeeTypCdListJSON = this.prjPrdPaySchMService.getSettFeeTypList();
        ModelAndView view = new ModelAndView("project/prjprdquatprps/prjPrdPaySchMCarNormalSettleFlowPage");
        view.addObject("settFeeTypCdListJSON", JSON.toJSONString(settFeeTypCdListJSON));
        view.addObject("settleWay", "正常结清");
        view.addObject("pay", pay);
        view.addObject("cst", cst);
        view.addObject("prj", prj);
        view.addObject("showBk_oCIn", showBk_oCIn);
        view.addObject("showBk_oCOut", showBk_oCOut);
        view.addObject("editInto", editInto);
        view.addObject("editOut", editOut);
        view.addObject("isDetail_bk", isDetail_bk);
        view.addObject("listPage", JSON.toJSONString(listPage));
        view.addObject("feeListPage", JSON.toJSONString(feeListPage));
        view.addObject("subFeeAmtTotalList", JSON.toJSONString(pay.getSubFeeAmtTotalList()));
        view.addObject("paySchId", paySchId);
        view.addObject("optba", openTheBillAdd);
        view.addObject("optbf", openTheBillForFinance);
        view.addObject("optbd", openTheBillForDetail);
        view.addObject("procInstId", procInstId);
        view.addObject("dtl", dtl);
        view.addObject("confirm", confirm);
        view.addObject("fileAuth", request.getParameter("fileAuth"));
        return view;
    }

    /**
     * 显示结清详情页面
     */
    @RequestMapping(value = "/showCarNormalSettlePage.do", method = {RequestMethod.GET})
    public ModelAndView showCarNormalSettlePage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toListPage", "加载PrjPrdPaySchM列表页面.", CurrentThreadContext.getCurrentUserName());
        String paySchId = request.getParameter("paySchId");//支付表ID
        String payPd = request.getParameter("payPd");
        PrjBscInfoVO prj = null;
        PrjPrdPaySchMVO pay = null;
        CstBscInfoVO cst = null;
        ListPageVO<PrjPrdPrpsFeeDetailVO> listPage = null;
        ListPageVO<PrjPrdPaySchDVO> feeListPage = null;
        PrjPrdDtlVO dtl = null;
        Integer startPd = null;
        try {
            if (StringUtils.isNotBlank(paySchId)) {
                PrjPrdPaySchMVO paySchMVO = this.prjPrdPaySchMService.getPrjPrdPaySettPayPd(Long.valueOf(paySchId), PrjPrdPaySchMConstant.PRJ_PRD_Pay_SCH_M_NORMAL, new Date());
                if (null != paySchMVO) {
                    startPd = paySchMVO.getStartLsPd().intValue();
                }
                pay = this.prjPrdPaySchMService.searchCarNormalSettleData(Long.valueOf(paySchId), new Date(), startPd);
                PrjPrdDtlQueryCondition qc = new PrjPrdDtlQueryCondition();
                qc.setPaySchId(Long.valueOf(paySchId));
                List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(qc);
                if (CollectionUtils.isNotEmpty(dtlList)) {
                    dtl = dtlList.get(0);
                }
                if (null != pay) {
                    cst = this.cstBscInfoService.selectDetailById(pay.getCstId());
                    prj = this.prjBscInfoService.selectById(pay.getPrjId());
                }
            }
            if (CollectionUtils.isNotEmpty(pay.getPrjPrdPayDetailList())) {
                listPage = new ListPageVO<PrjPrdPrpsFeeDetailVO>(pay.getPrjPrdPayDetailList(), pay.getPrjPrdPayDetailList().size());
                pay.setPrjQuatPrpsPaySchPage(listPage);
            }
            if (CollectionUtils.isNotEmpty(pay.getFeeDetailList())) {
                List<PrjPrdPaySchDVO> list = new ArrayList<PrjPrdPaySchDVO>();
                for (PrjPrdPaySchDVO prjPrdPaySchDVO : pay.getFeeDetailList()) {
                    if (prjPrdPaySchDVO.getFeeClsCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_PRPS)) {
                        list.add(prjPrdPaySchDVO);
                    }
                }

                //首期款合计项
                PrjPrdPaySchDVO tatal = new PrjPrdPaySchDVO();
                tatal.setFeeTypCdNm("首期款合计");
                tatal.setFeeAmt(pay.getFirstPayAmt());
                tatal.setPaidUpAmt(pay.getTotalFirstPayAmt().longValue());
                list.add(tatal);
                feeListPage = new ListPageVO<PrjPrdPaySchDVO>(list, list.size());
                //  feeListPage = new ListPageVO<PrjPrdPaySchDVO>(pay.getFeeDetailList(), pay.getFeeDetailList().size());
                pay.setFeeDetailListPage(feeListPage);
            }
            if (CollectionUtils.isNotEmpty(pay.getSubFeeAmtTotalList())) {
                for (PrjPrdPaySchDVO paySchDVO : pay.getSubFeeAmtTotalList()) {
                    paySchDVO.setFeeAmt(DecimalUtils.convertFenToYuan(paySchDVO.getFeeAmt().longValue()));
                }
            }
            List<SysDictionaryVO> settFeeTypCdListJSON = this.prjPrdPaySchMService.getSettFeeTypList();
            ModelAndView view = new ModelAndView("project/prjprdquatprps/prjPrdPaySchMCarNormalSettleDetailPage");
            view.addObject("pay", pay);
            view.addObject("cst", cst);
            view.addObject("prj", prj);
            view.addObject("subFeeAmtTotalList", JSON.toJSONString(pay.getSubFeeAmtTotalList()));
            view.addObject("listPage", JSON.toJSONString(listPage));
            view.addObject("feeListPage", JSON.toJSONString(feeListPage));
            view.addObject("paySchId", paySchId);
            view.addObject("dtl", dtl);
            view.addObject("settFeeTypCdListJSON", JSON.toJSONString(settFeeTypCdListJSON));
            view.addObject("model", "preview");// 代表结清申请预览
            return view;
        } catch (BaseException ex) {
            BaseLogUtils.info(logger, "showSettlePage", "显示结清详情页面查询失败.DATA:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
            throw ex;
        } catch (Exception ex) {
            BaseLogUtils.error(logger, "showSettlePage", "显示结清详情页面查询失败.DATA:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
            throw ex;
        }
    }

    /**
     * 显示分解之前的结清数据
     */
    @RequestMapping(value = "/searchCarNormalBeforeSplitSettleData.do", method = {RequestMethod.GET})
    public ModelAndView searchCarNormalbeforeSplitSettleData(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "searchBeforeSplitSettleData", "显示提前结清流程中详情页面.", CurrentThreadContext.getCurrentUserName());
        String paySchId = request.getParameter("paySchId");//支付表ID
        String isDetail_bk = request.getParameter("isDetail_bk");//标识是否详情_YAOXIURONG
        String showBk_oCIn = request.getParameter("showBk_oCIn");//加载我司收款账号维护页面
        String showBk_oCOut = request.getParameter("showBk_oCOut");//加载我司付款账号维护页面
        String editInto = request.getParameter("editInto");//我司付款_维护收款账号
        String editOut = request.getParameter("editOut");//我司付款_维护付款账号

        String openTheBillAdd = request.getParameter("optba");//标识是否需要开票新增列表页面_FUJINGRUN
        String openTheBillForFinance = request.getParameter("optbf");//标识是否显示财务开票列表页面_FUJINGRUN
        String openTheBillForDetail = request.getParameter("optbd");//是否显示开票详细列表页面_FUJINGRUN
        String procInstId = request.getParameter("processInstanceId");//流程实例ID_FUJINGRUN
        Integer payPd = 0;//提前结清时结清期数
        PrjBscInfoVO prj = null;
        PrjPrdPaySchMVO pay = null;
        CstBscInfoVO cst = null;
        ListPageVO<PrjPrdPrpsFeeDetailVO> listPage = null;
        ListPageVO<PrjPrdPaySchDVO> feeListPage = null;
        PrjPrdDtlVO dtl = null;
        Date applyDate = null;
        try {
            if (StringUtils.isNotBlank(paySchId)) {
                // 查找结清期数
                PrjPrdPaySchMVO schMVO = getSchMVO(procInstId, Long.valueOf(paySchId));
                payPd = schMVO.getStlPd();

                PrjStlMVO prjStlMVO = this.prjStlMService.selectByPaySchMId(Long.valueOf(paySchId), PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_CST);
                if (null == prjStlMVO) {
                    pay = this.prjPrdPaySchMService.searchCarNormalSettleData(Long.valueOf(paySchId), null, Integer.valueOf(payPd));
                } else {
                    pay = this.prjPrdPaySchMService.searchCarNormalSettleDataForFlow(Long.valueOf(paySchId), null, Integer.valueOf(payPd));
                }
                PrjPrdDtlQueryCondition qc = new PrjPrdDtlQueryCondition();
                qc.setPaySchId(Long.valueOf(paySchId));
                List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(qc);
                if (CollectionUtils.isNotEmpty(dtlList)) {
                    dtl = dtlList.get(0);
                }
                if (null != pay) {
                    cst = this.cstBscInfoService.selectDetailById(pay.getCstId());
                    prj = this.prjBscInfoService.selectById(pay.getPrjId());
                }
                if (CollectionUtils.isNotEmpty(pay.getPrjPrdPayDetailList())) {
                    listPage = new ListPageVO<PrjPrdPrpsFeeDetailVO>(pay.getPrjPrdPayDetailList(), pay.getPrjPrdPayDetailList().size());
                    pay.setPrjQuatPrpsPaySchPage(listPage);
                }
                if (CollectionUtils.isNotEmpty(pay.getFeeDetailList())) {
                    List<PrjPrdPaySchDVO> list = new ArrayList<PrjPrdPaySchDVO>();
                    for (PrjPrdPaySchDVO prjPrdPaySchDVO : pay.getFeeDetailList()) {
                        if (prjPrdPaySchDVO.getFeeClsCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_PRPS)) {
                            list.add(prjPrdPaySchDVO);
                        }
                    }
                    //首期款合计项
                    PrjPrdPaySchDVO tatal = new PrjPrdPaySchDVO();
                    tatal.setFeeTypCdNm("首期款合计");
                    tatal.setFeeAmt(pay.getFirstPayAmt());
                    tatal.setPaidUpAmt(pay.getTotalFirstPayAmt().longValue());
                    list.add(tatal);
                    feeListPage = new ListPageVO<PrjPrdPaySchDVO>(list, list.size());
                    pay.setFeeDetailListPage(feeListPage);
                }
                if (CollectionUtils.isNotEmpty(pay.getSubFeeAmtTotalList())) {
                    for (PrjPrdPaySchDVO paySchDVO : pay.getSubFeeAmtTotalList()) {
                        paySchDVO.setFeeAmt(DecimalUtils.convertFenToYuan(paySchDVO.getFeeAmt().longValue()));
                    }
                }

            }
        } catch (BaseException ex) {
            BaseLogUtils.info(logger, "preSettleFlowPage", "结清流程中页面查询失败.DATA:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
        } catch (Exception ex) {
            BaseLogUtils.error(logger, "preSettleFlowPage", "结清流程中页面查询失败.DATA:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
        }
        List<SysDictionaryVO> settFeeTypCdListJSON = this.prjPrdPaySchMService.getSettFeeTypList();
        //费用类型
        ModelAndView view = new ModelAndView("project/prjprdquatprps/prjPrdPaySchMCarNormalSplitSettleFlowPage");
        view.addObject("pay", pay);
        view.addObject("cst", cst);
        view.addObject("prj", prj);
        view.addObject("dtl", dtl);
        view.addObject("showBk_oCIn", showBk_oCIn);
        view.addObject("isDetail_bk", isDetail_bk);
        view.addObject("showBk_oCOut", showBk_oCOut);
        view.addObject("editInto", editInto);
        view.addObject("editOut", editOut);
        view.addObject("subFeeAmtTotalList", JSON.toJSONString(pay.getSubFeeAmtTotalList()));
        view.addObject("listPage", JSON.toJSONString(listPage));
        view.addObject("feeListPage", JSON.toJSONString(feeListPage));
        view.addObject("paySchId", paySchId);
        view.addObject("settFeeTypCdListJSON", JSON.toJSONString(settFeeTypCdListJSON));
        view.addObject("optba", openTheBillAdd);
        view.addObject("optbf", openTheBillForFinance);
        view.addObject("optbd", openTheBillForDetail);
        view.addObject("procInstId", procInstId);
        return view;
    }


    /**
     * 显示车立行的结清数据
     */
    @RequestMapping(value = "/searchPrjPrdPaySchTMNormalSettleData.do", method = {RequestMethod.GET})
    public ModelAndView searchPrjPrdPaySchTMNormalSettleData(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "searchPrjPrdPaySchTMSettleData", "显示提前结清流程中详情页面.", CurrentThreadContext.getCurrentUserName());
        String paySchId = request.getParameter("paySchId");//支付表ID

        PrjBscInfoVO prj = null;
        PrjPrdPaySchMVO pay = null;
        CstBscInfoVO cst = null;
        ListPageVO<PrjPrdPrpsFeeDetailVO> listPage = null;
        ListPageVO<PrjPrdPaySchTDVO> feeListPage = null;
        PrjPrdDtlVO dtl = null;
        double firstPayAmt = 0d;
        double totalFirstPayAmt = 0d;
        try {
            if (StringUtils.isNotBlank(paySchId)) {
                pay = this.prjPrdPaySchMService.searchPrjPrdSchTMSettleDataForQCJR(Long.valueOf(paySchId));
                PrjPrdDtlQueryCondition qc = new PrjPrdDtlQueryCondition();
                qc.setPaySchId(Long.valueOf(paySchId));
                List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(qc);
                if (CollectionUtils.isNotEmpty(dtlList)) {
                    dtl = dtlList.get(0);
                }
                if (null != pay) {
                    cst = this.cstBscInfoService.selectDetailById(pay.getCstId());
                    prj = this.prjBscInfoService.selectById(pay.getPrjId());
                }
                PrjPrdPaySchTDQC tdQc = new PrjPrdPaySchTDQC();
                tdQc.setPaySchId(Long.valueOf(paySchId));
                tdQc.setPayPd(Long.valueOf(PrjQuatPrpsConstant.CODE_PRJ_PRD_PAY_PD));
                tdQc.setSysCd(CurrentThreadContext.getCurrentSysCd());
                tdQc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
                List<PrjPrdPaySchTDVO> dtList = this.prjPrdPaySchTDService.searchList(tdQc);

                if (CollectionUtils.isNotEmpty(pay.getPrjPrdPayDetailList())) {
                    listPage = new ListPageVO<PrjPrdPrpsFeeDetailVO>(pay.getPrjPrdPayDetailList(), pay.getPrjPrdPayDetailList().size());
                    pay.setPrjQuatPrpsPaySchPage(listPage);
                }
                if (CollectionUtils.isNotEmpty(dtList)) {
                    List<PrjPrdPaySchTDVO> list = new ArrayList<PrjPrdPaySchTDVO>();
                    for (PrjPrdPaySchTDVO prjPrdPaySchDVO : dtList) {
                        if (prjPrdPaySchDVO.getFeeClsCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_PRPS)) {
                            if (prjPrdPaySchDVO.getCntWayCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_DOWNPAY)) {
                                firstPayAmt = DecimalUtils.add(firstPayAmt, prjPrdPaySchDVO.getFeeAmt());
                                totalFirstPayAmt = DecimalUtils.add(totalFirstPayAmt, prjPrdPaySchDVO.getArAmt());
                            }
                            prjPrdPaySchDVO.setFeeAmt(DecimalUtils.convertFenToYuan(prjPrdPaySchDVO.getFeeAmt()).longValue());
                            prjPrdPaySchDVO.setArAmt(DecimalUtils.convertFenToYuan(prjPrdPaySchDVO.getArAmt()).longValue());
                            list.add(prjPrdPaySchDVO);

                        }
                    }
                    //首期款合计项
                    PrjPrdPaySchTDVO tatal = new PrjPrdPaySchTDVO();
                    tatal.setFeeTypCdNm("首期款合计");
                    tatal.setFeeAmt(DecimalUtils.convertFenToYuan(Double.valueOf(firstPayAmt).longValue()).longValue());
                    tatal.setPaidUpAmt(DecimalUtils.convertFenToYuan(Double.valueOf(totalFirstPayAmt).longValue()).longValue());
                    list.add(tatal);
                    feeListPage = new ListPageVO<PrjPrdPaySchTDVO>(list, list.size());
                }
                if (CollectionUtils.isNotEmpty(pay.getSubFeeAmtTotalList())) {
                    for (PrjPrdPaySchDVO paySchDVO : pay.getSubFeeAmtTotalList()) {
                        paySchDVO.setFeeAmt(DecimalUtils.convertFenToYuan(paySchDVO.getFeeAmt().longValue()));
                    }
                }

            }
        } catch (BaseException ex) {
            BaseLogUtils.info(logger, "preSettleFlowPage", "结清流程中页面查询失败.DATA:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
        } catch (Exception ex) {
            BaseLogUtils.error(logger, "preSettleFlowPage", "结清流程中页面查询失败.DATA:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
        }
        //费用类型
        ModelAndView view = new ModelAndView("project/prjprdquatprps/prjPrdPaySchTMCarNormalSettleFlowPage");
        view.addObject("pay", pay);
        view.addObject("cst", cst);
        view.addObject("prj", prj);
        view.addObject("dtl", dtl);
        view.addObject("listPage", JSON.toJSONString(listPage));
        view.addObject("feeListPage", JSON.toJSONString(feeListPage));
        view.addObject("paySchId", paySchId);
        return view;
    }

    /**
     * 显示车立行的结清数据
     */
    @RequestMapping(value = "/searchPrjPrdPaySchTMPreSettleData.do", method = {RequestMethod.GET})
    public ModelAndView searchPrjPrdPaySchTMPreSettleData(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "searchPrjPrdPaySchTMPreSettleData", "显示提前结清流程中详情页面.", CurrentThreadContext.getCurrentUserName());
        String paySchId = request.getParameter("paySchId");//支付表ID

        PrjBscInfoVO prj = null;
        PrjPrdPaySchMVO pay = null;
        CstBscInfoVO cst = null;
        ListPageVO<PrjPrdPrpsFeeDetailVO> listPage = null;
        ListPageVO<PrjPrdPaySchTDVO> feeListPage = null;
        PrjPrdDtlVO dtl = null;
        try {
            if (StringUtils.isNotBlank(paySchId)) {
                pay = this.prjPrdPaySchMService.searchPrjPrdSchTMSettleDataForQCJR(Long.valueOf(paySchId));
                PrjPrdDtlQueryCondition qc = new PrjPrdDtlQueryCondition();
                qc.setPaySchId(Long.valueOf(paySchId));
                List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(qc);
                if (CollectionUtils.isNotEmpty(dtlList)) {
                    dtl = dtlList.get(0);
                }
                if (null != pay) {
                    cst = this.cstBscInfoService.selectDetailById(pay.getCstId());
                    prj = this.prjBscInfoService.selectById(pay.getPrjId());
                }
                PrjPrdPaySchTDQC tdQc = new PrjPrdPaySchTDQC();
                tdQc.setPaySchId(Long.valueOf(paySchId));
                tdQc.setSysCd(CurrentThreadContext.getCurrentSysCd());
                tdQc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
                tdQc.setPayPd(Long.valueOf(PrjQuatPrpsConstant.CODE_PRJ_PRD_PAY_PD));
                List<PrjPrdPaySchTDVO> dtList = this.prjPrdPaySchTDService.searchList(tdQc);
                if (CollectionUtils.isNotEmpty(pay.getPrjPrdPayDetailList())) {
                    List<PrjPrdPrpsFeeDetailVO> feeList = null;
                    double totalRnt = 0d;//租金
                    double totalPrint = 0d;//本金
                    double totalInt = 0d;//利息
                    if (pay.getStlPd().intValue() != 0) {
                        //查询流程中临时状态的期数
                        Integer payPdFlow = pay.getStlPd();
                        feeList = new ArrayList<PrjPrdPrpsFeeDetailVO>();
                        for (PrjPrdPrpsFeeDetailVO payDetail : pay.getPrjPrdPayDetailList()) {
                            if (payDetail.getPayPd().intValue() < Integer.valueOf(payPdFlow).intValue()) {
                                totalRnt = DecimalUtils.add(totalRnt, payDetail.getRntAmt());
                                totalPrint = DecimalUtils.add(totalPrint, payDetail.getPrinAmt());
                                totalInt = DecimalUtils.add(totalInt, payDetail.getIntAmt());
                                feeList.add(payDetail);
                            }
                            if (payDetail.getPayPd().intValue() == Integer.valueOf(payPdFlow).intValue()) {
                                payDetail.setRntAmt(DecimalUtils.sub(pay.getTotalRntAmt(), totalRnt));
                                payDetail.setPrinAmt(DecimalUtils.sub(pay.getTotalPrinAmt(), totalPrint));
                                payDetail.setIntAmt(DecimalUtils.sub(pay.getTotalIntAmt(), totalInt));
                                payDetail.setRemPrinAmt(0d);
                                payDetail.setIsDel(PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                                feeList.add(payDetail);
                            }
                        }


                    } else {
                        feeList = pay.getPrjPrdPayDetailList();
                    }
                    listPage = new ListPageVO<PrjPrdPrpsFeeDetailVO>(feeList, feeList.size());
                    pay.setPrjQuatPrpsPaySchPage(listPage);
                }

                double firstPayAmt = 0d;
                double totalFirstPayAmt = 0d;
                if (CollectionUtils.isNotEmpty(dtList)) {
                    List<PrjPrdPaySchTDVO> list = new ArrayList<PrjPrdPaySchTDVO>();
                    for (PrjPrdPaySchTDVO prjPrdPaySchDVO : dtList) {
                        if (prjPrdPaySchDVO.getFeeClsCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_PRPS)) {
                            if (prjPrdPaySchDVO.getCntWayCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_DOWNPAY)) {
                                firstPayAmt = DecimalUtils.add(firstPayAmt, prjPrdPaySchDVO.getFeeAmt());
                                totalFirstPayAmt = DecimalUtils.add(totalFirstPayAmt, prjPrdPaySchDVO.getArAmt());
                            }
                            prjPrdPaySchDVO.setFeeAmt(DecimalUtils.convertFenToYuan(prjPrdPaySchDVO.getFeeAmt()).longValue());
                            prjPrdPaySchDVO.setArAmt(DecimalUtils.convertFenToYuan(prjPrdPaySchDVO.getArAmt()).longValue());
                            list.add(prjPrdPaySchDVO);

                        }
                    }
                    //首期款合计项
                    PrjPrdPaySchTDVO tatal = new PrjPrdPaySchTDVO();
                    tatal.setFeeTypCdNm("首期款合计");
                    tatal.setFeeAmt(DecimalUtils.convertFenToYuan(Double.valueOf(firstPayAmt).longValue()).longValue());
                    tatal.setPaidUpAmt(DecimalUtils.convertFenToYuan(Double.valueOf(totalFirstPayAmt).longValue()).longValue());
                    list.add(tatal);
                    feeListPage = new ListPageVO<PrjPrdPaySchTDVO>(list, list.size());
                }
                if (CollectionUtils.isNotEmpty(pay.getSubFeeAmtTotalList())) {
                    for (PrjPrdPaySchDVO paySchDVO : pay.getSubFeeAmtTotalList()) {
                        paySchDVO.setFeeAmt(DecimalUtils.convertFenToYuan(paySchDVO.getFeeAmt().longValue()));
                    }
                }

            }
        } catch (BaseException ex) {
            BaseLogUtils.info(logger, "preSettleFlowPage", "结清流程中页面查询失败.DATA:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
        } catch (Exception ex) {
            BaseLogUtils.error(logger, "preSettleFlowPage", "结清流程中页面查询失败.DATA:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
        }
        //费用类型
        ModelAndView view = new ModelAndView("project/prjprdquatprps/prjPrdPaySchTMCarPreSettleFlowPage");
        view.addObject("pay", pay);
        view.addObject("cst", cst);
        view.addObject("prj", prj);
        view.addObject("dtl", dtl);
        view.addObject("listPage", JSON.toJSONString(listPage));
        view.addObject("feeListPage", JSON.toJSONString(feeListPage));
        view.addObject("paySchId", paySchId);
        return view;
    }


    /**
     * 设置起租日(工行卡贷)
     */
    @RequestMapping(value = "/toModifyPayDtListPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toModifyPayDtListPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toModifyPayDtListPage", "加载toModifyPayDtListPage Add页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView mav = new ModelAndView("project/prjpayschm/toModifyPayDtList");
        return mav;
    }

    /**
     * 支付表管理
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/getLsDatePrjPrdPaySchMList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object getLsDatePrjPrdPaySchMList(HttpServletRequest request, HttpServletResponse response) {
        String currentPage = request.getParameter("page");
        String pageSize = request.getParameter("pagesize");
        String lsCntNo = request.getParameter("lsCntNo");//合同编号
        String paySchNo = request.getParameter("paySchNo");//支付表号
        Pager page = new Pager();
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setCurrentPage(Integer.parseInt(currentPage));
        }

        if (StringUtils.isNotEmpty(pageSize)) {
            page.setEveryPage(Integer.MAX_VALUE);
        }
        PrjPrdPaySchMQueryCondition qc = new PrjPrdPaySchMQueryCondition();
        if (StringUtils.isNotBlank(paySchNo)) {
            qc.setPaySchNo(paySchNo);
        }
        if (StringUtils.isNotBlank(lsCntNo)) {
            qc.setLsCntNo(lsCntNo);
        }
        Long usrId = null;
        String orgCd = "";
        if (StringUtils.isNotBlank(lsCntNo)) {
            PrjBscInfoQueryCondition prjQc = new PrjBscInfoQueryCondition();
            prjQc.setLsCntNo(lsCntNo);
            List<PrjBscInfoVO> prjBscInfoList = this.prjBscInfoService.searchPrjBscInfoList(prjQc);
            if (CollectionUtils.isNotEmpty(prjBscInfoList)) {
                usrId = prjBscInfoList.get(0).getCstMgrId();
                orgCd = prjBscInfoList.get(0).getBuOrgCd();
            }
        } else {
            if (StringUtils.isNotBlank(paySchNo)) {
                PrjPrdPaySchMQueryCondition schMQc = new PrjPrdPaySchMQueryCondition();
                schMQc.setPaySchNo(paySchNo);
                List<PrjPrdPaySchMVO> list = this.prjPrdPaySchMService.searchList(schMQc);
                if (CollectionUtils.isNotEmpty(list)) {
                    PrjBscInfoVO prjBscInfoVO = prjBscInfoService.selectById(list.get(0).getPrjId());
                    usrId = prjBscInfoVO.getCstMgrId();
                    orgCd = prjBscInfoVO.getBuOrgCd();
                }

            }
        }
        if (null == usrId || StringUtils.isBlank(orgCd)) {
            return new ListPageVO<PrjPrdPaySchMVO>();
        }
        qc.setUsrId(usrId);
        qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
        qc.setOrgCd(orgCd);
        qc.setIsDel(BaseConstant.IS_YESNO_NO);
        page.setCondition(qc);
        BaseLogUtils.info(logger, "initPrjPrdPaySchMList", "初始化PrjPrdPaySchM列表页面数据.DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
        Pager pager = null;
        pager = this.prjPrdPaySchMService.selectPrjPrdPaySchMMgrListPage(page);
        List<PrjPrdPaySchMVO> list = (List<PrjPrdPaySchMVO>) pager.getResultList();
        ListPageVO<PrjPrdPaySchMVO> listPage = new ListPageVO<PrjPrdPaySchMVO>(list, pager.getTotalCount());
        return listPage;
    }

    /**
     * 修改起租日
     */
    @RequestMapping(value = "/modifyPrjPaySchMLsDt.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object modifyPrjPaySchMLsDt(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
        PrjPrdPaySchDVO detail = null;//获取参数
        String prjId = request.getParameter("prjId");
        String paySchId = request.getParameter("id");
        String buOrgCd = request.getParameter("buOrgCd");
        String payAmt = request.getParameter("thdPayAmt");//放款金额
        String lsDt = request.getParameter("lsDt");//起租日
        DataResultVO resultVO = new DataResultVO();
        try {
            PrjPrdPaySchMVO schMVO = new PrjPrdPaySchMVO();
            if (StringUtils.isNotBlank(prjId)) {
                schMVO.setPrjId(Long.valueOf(prjId));
            }
            if (StringUtils.isNotBlank(paySchId)) {
                schMVO.setId(Long.valueOf(paySchId));
            }
            if (StringUtils.isNotBlank(buOrgCd)) {
                schMVO.setBuOrgCd(buOrgCd);
            }
            if (StringUtils.isNotBlank(payAmt)) {
                schMVO.setThdPayAmt(DecimalUtils.convertYuanToFen(Double.valueOf(payAmt)));
            }
            if (StringUtils.isBlank(lsDt)) {
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "起租日期不能为空!");
            }
            schMVO.setLsDt(DateUtils.formatStringToDate(lsDt, DateUtils.YYYY_MM_DD));
            schMVO.setThdPayDt(DateUtils.formatStringToDate(lsDt, DateUtils.YYYY_MM_DD));
            schMVO.setPayerStsCd(FlowConstant.FLOW_CHECK_STATE_PASS);
            boolean flag = prjPrdPaySchMService.modifyPrjPrdSchMPayDate(schMVO);
            if (flag) {
                resultVO.setSuccess(BaseConstant.IS_YESNO_YES);
                resultVO.setInfo("修改成功！");
            } else {
                resultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                resultVO.setInfo("修改失败！");
            }
            BaseLogUtils.info(logger, "modifyLsPdDt", "修改起租日数据成功," + ".DATA:" + JSONObject.toJSONString(detail), CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            resultVO = new DataResultVO();
            resultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            resultVO.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.info(logger, "modifyLsPdDt", "修改起租日数据失败.DATA:" + JSONObject.toJSONString(detail) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            resultVO = new DataResultVO();
            resultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            resultVO.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.error(logger, "modifyLsPdDt", "修改起租日数据失败,系统错误.DATA:" + JSONObject.toJSONString(detail) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return resultVO;
    }


    /**
     * 显示提前结清添加费用项页面
     */
    @RequestMapping(value = "/addZCCarPreSettleFeePage.do", method = {RequestMethod.GET})
    public ModelAndView addZCCarPreSettleFeePage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "addZCCarPreSettleFeePage", "显示提前结清详情页面.", CurrentThreadContext.getCurrentUserName());
        String paySchId = request.getParameter("paySchId");//支付表ID
        String addSetDateFlag = request.getParameter("addSetDateFlag");//当结清时间为
        String isDetail = request.getParameter("isDetail");
        String taskDefKey = request.getParameter("taskDefKey");// 例如：FLOW_00000001_063_001_001

        Integer payPd = null;//提前结清时结清期数
        PrjBscInfoVO prj = null;
        PrjPrdPaySchMVO pay = null;
        CstBscInfoVO cst = null;
        ListPageVO<PrjPrdPrpsFeeDetailVO> listPage = null;
        ListPageVO<PrjPrdPaySchDVO> feeListPage = null;
        PrjPrdDtlVO dtl = null;
        Date applyDate = null;
        ModelAndView view = new ModelAndView("project/prjPrdPaySchSett/prjPrdPaySchMPerSettleAddFeePage");
        try {
            if (StringUtils.isNotBlank(paySchId)) {
                //查询支付表保存的结清期数，没有查找流程发起时的结清期数
                PrjStlMVO stlMVO = this.prjStlMService.selectByPaySchMId(Long.valueOf(paySchId), PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_CST);

                // 查找结清期数
                PrjPrdPaySchMVO schMVO = getSchMVO("", Long.valueOf(paySchId));
                payPd = schMVO.getStlPd();

                pay = this.prjPrdPaySchMService.searchPreSettleData(Long.valueOf(paySchId), null, Integer.valueOf(payPd));
                if (null != pay) {
                    PrjPrdDtlQueryCondition qc = new PrjPrdDtlQueryCondition();
                    qc.setPaySchId(pay.getWsPaySchId());
                    List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(qc);
                    if (CollectionUtils.isNotEmpty(dtlList)) {
                        dtl = dtlList.get(0);
                    }
                    cst = this.cstBscInfoService.selectDetailById(pay.getCstId());
                    prj = this.prjBscInfoService.selectById(pay.getPrjId());
                    // 申请时间
                    applyDate = pay.getApplyDt();
                    if (null != stlMVO && null != applyDate && null != stlMVO.getStlStDt()
                            && org.apache.commons.lang3.time.DateUtils.isSameDay(applyDate, stlMVO.getStlStDt())) {
                        if (null != stlMVO.getRmS03ArTotAmt()) {
                            pay.setLastPrintAmt(stlMVO.getRmS03ArTotAmt());
                        }
                        if (null != stlMVO.getRmS02ArTotAmt()) {
                            pay.setLastIntAmt(stlMVO.getRmS02ArTotAmt());
                        }

                        if (null != stlMVO.getRmS03CurrAmt()) {
                            pay.setCurrentPrintAmt(stlMVO.getRmS03CurrAmt());
                        }
                        if (null != stlMVO.getRmS02CurrAmt()) {
                            pay.setCurrentIntAmt(stlMVO.getRmS02CurrAmt());
                        }
                        if (null != stlMVO.getStlPenaltyAmt()) {
                            pay.setPenaltyAmt(stlMVO.getStlPenaltyAmt());
                        }
                        if (null != stlMVO.getStlOverdueAmt()) {
                            pay.setOverdueAmt(stlMVO.getStlOverdueAmt());
                        }
                        if (null != stlMVO.getStlAmt()) {
                            pay.setStlAmt(stlMVO.getStlAmt().longValue());
                            pay.setFinalPayAmt(stlMVO.getStlAmt());
                            pay.setTotalSettAmt(stlMVO.getStlAmt());
                        }
                    }
                }
            }
            if (CollectionUtils.isNotEmpty(pay.getPrjPrdPayDetailList())) {
                List<PrjPrdPrpsFeeDetailVO> feeList = null;
                double totalRnt = 0d;//租金
                double totalPrint = 0d;//本金
                double totalInt = 0d;//利息
                if (payPd != 0) {
                    //查询流程中临时状态的期数
                    Integer payPdFlow = null;
                    List<PrjPrdPaySchDVO> list = this.prjPrdPaySchDService.selectPaySchByDelStatusAndPaySchId(Long.valueOf(paySchId), PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                    if (CollectionUtils.isNotEmpty(list)) {
                        payPdFlow = list.get(0).getPayPd();
                        feeList = new ArrayList<PrjPrdPrpsFeeDetailVO>();
                        for (PrjPrdPrpsFeeDetailVO payDetail : pay.getPrjPrdPayDetailList()) {
                            if (payDetail.getPayPd().intValue() < Integer.valueOf(payPdFlow).intValue()) {
                                totalRnt = DecimalUtils.add(totalRnt, payDetail.getRntAmt());
                                totalPrint = DecimalUtils.add(totalPrint, payDetail.getPrinAmt());
                                totalInt = DecimalUtils.add(totalInt, payDetail.getIntAmt());
                                feeList.add(payDetail);
                            }
                            if (payDetail.getPayPd().intValue() == Integer.valueOf(payPdFlow).intValue()) {
                                payDetail.setRntAmt(DecimalUtils.sub(pay.getTotalRntAmt(), totalRnt));
                                payDetail.setPrinAmt(DecimalUtils.sub(pay.getTotalPrinAmt(), totalPrint));
                                payDetail.setIntAmt(DecimalUtils.sub(pay.getTotalIntAmt(), totalInt));
                                payDetail.setRemPrinAmt(0d);
                                payDetail.setIsDel(PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                                feeList.add(payDetail);
                            }
                        }
                    } else {
                        feeList = pay.getPrjPrdPayDetailList();
                    }

                } else {
                    feeList = pay.getPrjPrdPayDetailList();
                }
                listPage = new ListPageVO<PrjPrdPrpsFeeDetailVO>(feeList, feeList.size());
                pay.setPrjQuatPrpsPaySchPage(listPage);
            }

            if (CollectionUtils.isNotEmpty(pay.getFeeDetailList())) {
                List<PrjPrdPaySchDVO> list = new ArrayList<PrjPrdPaySchDVO>();
                for (PrjPrdPaySchDVO prjPrdPaySchDVO : pay.getFeeDetailList()) {
                    if (prjPrdPaySchDVO.getFeeClsCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_PRPS)) {
                        list.add(prjPrdPaySchDVO);
                    }
                }
                //首期款合计项
                PrjPrdPaySchDVO tatal = new PrjPrdPaySchDVO();
                tatal.setFeeTypCdNm("首期款合计");
                tatal.setFeeAmt(pay.getFirstPayAmt());
                tatal.setPaidUpAmt(pay.getTotalFirstPayAmt().longValue());
                list.add(tatal);
                feeListPage = new ListPageVO<PrjPrdPaySchDVO>(list, list.size());
                pay.setFeeDetailListPage(feeListPage);
            }
            if (CollectionUtils.isNotEmpty(pay.getSubFeeAmtTotalList())) {
                for (PrjPrdPaySchDVO paySchDVO : pay.getSubFeeAmtTotalList()) {
                    paySchDVO.setFeeAmt(DecimalUtils.convertFenToYuan(paySchDVO.getFeeAmt().longValue()));
                }
            }


            //费用类型
            List<SysDictionaryVO> settFeeTypCdListJSON = this.prjPrdPaySchMService.getSettFeeTypList();

            view.addObject("pay", pay);
            view.addObject("cst", cst);
            view.addObject("prj", prj);
            view.addObject("dtl", dtl);
            view.addObject("subFeeAmtTotalList", JSON.toJSONString(pay.getSubFeeAmtTotalList()));
            view.addObject("listPage", JSON.toJSONString(listPage));
            view.addObject("feeListPage", JSON.toJSONString(feeListPage));
            view.addObject("paySchId", paySchId);
            view.addObject("settFeeTypCdListJSON", JSON.toJSONString(settFeeTypCdListJSON));
            view.addObject("isDetail", isDetail);
            view.addObject("taskDefKey", taskDefKey);
            view.addObject("wsPaySchId", pay.getWsPaySchId());
            String isDetail_bk = request.getParameter("isDetail_bk");//标识是否详情_YAOXIURONG
            String showBk_oCIn = request.getParameter("showBk_oCIn");//加载我司收款账号维护页面
            String showBk_oCOut = request.getParameter("showBk_oCOut");//加载我司付款账号维护页面
            String editInto = request.getParameter("editInto");//我司付款_维护收款账号
            String editOut = request.getParameter("editOut");//我司付款_维护付款账号
            //如果为空 设置为1 使流程中每个节点都可以查看账户信息
            if (StringUtils.isEmpty(showBk_oCIn) && StringUtils.isEmpty(showBk_oCOut)) {
                showBk_oCIn = "1";
                showBk_oCOut = "1";
                isDetail_bk = "1";
            }
            view.addObject("showBk_oCIn", showBk_oCIn);
            view.addObject("isDetail_bk", isDetail_bk);
            view.addObject("showBk_oCOut", showBk_oCOut);
            view.addObject("editInto", editInto);
            view.addObject("editOut", editOut);
            view.addObject("fileAuth", request.getParameter("fileAuth"));
        } catch (BaseException ex) {
            BaseLogUtils.info(logger, "addPreSettleFeePage", "结清添加费用项页面查询失败.DATA:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
        } catch (Exception ex) {
            BaseLogUtils.error(logger, "addPreSettleFeePage", "结清添加费用项页面查询失败.DATA:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
        }
        return view;
    }

    /**
     * 显示提前结清详情页面
     */
    @RequestMapping(value = "/showZCCarPreSettlePage.do", method = {RequestMethod.GET})
    public ModelAndView showZCCarPreSettlePage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "showPreSettlePage", "显示提前结清详情页面.", CurrentThreadContext.getCurrentUserName());
        String paySchId = request.getParameter("paySchId");//支付表ID
        String payPdStr = request.getParameter("payPd");//提前结清时结清期数
        PrjBscInfoVO prj = null;
        PrjPrdPaySchMVO pay = null;
        CstBscInfoVO cst = null;
        ListPageVO<PrjPrdPrpsFeeDetailVO> listPage = null;
        ListPageVO<PrjPrdPaySchDVO> feeListPage = null;
        PrjPrdDtlVO dtl = null;
        Integer actPayPd = null;//实际换到的期数
        Integer payPd = null;//期数
        Integer zckcFlag = BaseConstant.IS_YESNO_NO;// 专车客车标识
        if (StringUtils.isNotBlank(payPdStr)) {
            payPd = Integer.valueOf(payPdStr);
        }
        ModelAndView view = new ModelAndView("project/prjPrdPaySchSett/prjPrdPaySchMPerSettleDetailPage");
        try {
            if (StringUtils.isNotBlank(paySchId)) {
                PrjPrdDtlQueryCondition qc = new PrjPrdDtlQueryCondition();
                qc.setPaySchId(Long.valueOf(paySchId));
                List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(qc);
                if (CollectionUtils.isNotEmpty(dtlList)) {
                    dtl = dtlList.get(0);
                }
                pay = this.prjPrdPaySchMService.searchPreSettleData(Long.valueOf(paySchId), new Date(), Integer.valueOf(payPd));
                if (null != pay) {
                    cst = this.cstBscInfoService.selectDetailById(pay.getCstId());
                    prj = this.prjBscInfoService.selectById(pay.getPrjId());
                    if (prj.getCstMgrOrgCd().contains(PrjBscInfoConstant.CODE_ORG_CD_KCRZ)) {
                        zckcFlag = BaseConstant.IS_YESNO_YES;
                    }
                }
            }

            if (CollectionUtils.isNotEmpty(pay.getPrjPrdPayDetailList())) {
                List<PrjPrdPrpsFeeDetailVO> feeList = null;
                double totalRnt = 0d;//租金
                double totalPrint = 0d;//本金
                double totalInt = 0d;//利息
                double actTotalRnt = 0d;//实际剩余租金
                double actTotalPrint = 0d;//实际本金
                double actTotalInt = 0d;//实际利息
                if (null != payPd) {
                    feeList = new ArrayList<PrjPrdPrpsFeeDetailVO>();
                    //查找实际已经还的期数，如果期数大于当前选择的期数
                    for (PrjPrdPaySchDVO prjPrdPaySchDVO : pay.getPrjPrdPaySchDList()) {
                        if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_RNT_PRICE)) {
                            if (null == prjPrdPaySchDVO.getPaidUpAmt() || prjPrdPaySchDVO.getFeeAmt().longValue() != prjPrdPaySchDVO.getPaidUpAmt()) {
                                actPayPd = prjPrdPaySchDVO.getPayPd();
                                break;
                            }
                        }
                    }
                    for (PrjPrdPaySchDVO prjPrdPaySchDVO : pay.getPrjPrdPaySchDList()) {
                        if (null != actPayPd && prjPrdPaySchDVO.getPayPd() >= actPayPd) {
                            double arAmt = DecimalUtils.convertFenToYuan(prjPrdPaySchDVO.getArAmt());
                            if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_RNT_PRICE)) {
                                actTotalRnt = DecimalUtils.add(actTotalRnt, arAmt);
                            }
                            if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_PRINT_PRICE)) {
                                actTotalPrint = DecimalUtils.add(actTotalPrint, arAmt);
                            }
                            if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_INT_PRICE)) {
                                actTotalInt = DecimalUtils.add(actTotalInt, arAmt);
                            }
                        }
                    }
                    for (PrjPrdPrpsFeeDetailVO payDetail : pay.getPrjPrdPayDetailList()) {
                        if (actPayPd < payPd) {
                            if (payDetail.getPayPd().intValue() < Integer.valueOf(payPd).intValue()) {
                                totalRnt = DecimalUtils.add(totalRnt, payDetail.getRntAmt());
                                totalPrint = DecimalUtils.add(totalPrint, payDetail.getPrinAmt());
                                totalInt = DecimalUtils.add(totalInt, payDetail.getIntAmt());
                                feeList.add(payDetail);
                            }
                            if (payDetail.getPayPd().intValue() == Integer.valueOf(payPd).intValue()) {
                                payDetail.setRntAmt(DecimalUtils.sub(pay.getTotalRntAmt(), totalRnt));
                                payDetail.setPrinAmt(DecimalUtils.sub(pay.getTotalPrinAmt(), totalPrint));
                                payDetail.setIntAmt(DecimalUtils.sub(pay.getTotalIntAmt(), totalInt));
                                payDetail.setRemPrinAmt(0d);
                                payDetail.setIsDel(PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                                feeList.add(payDetail);
                            }
                        } else {
                            if (payDetail.getPayPd().intValue() < Integer.valueOf(actPayPd).intValue()) {
                                totalRnt = DecimalUtils.add(totalRnt, payDetail.getRntAmt());
                                totalPrint = DecimalUtils.add(totalPrint, payDetail.getPrinAmt());
                                totalInt = DecimalUtils.add(totalInt, payDetail.getIntAmt());
                                feeList.add(payDetail);
                            }
                            if (payDetail.getPayPd().intValue() == Integer.valueOf(actPayPd).intValue()) {
                                //提前还款剩余的期次为支付表实际剩余的租金、本金、利息
                                payDetail.setRntAmt(actTotalRnt);
                                payDetail.setPrinAmt(actTotalPrint);
                                payDetail.setIntAmt(actTotalInt);
                                payDetail.setRemPrinAmt(0d);
                                payDetail.setIsDel(PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                                feeList.add(payDetail);
                            }
                        }
                    }
                } else {
                    feeList = pay.getPrjPrdPayDetailList();
                }
                listPage = new ListPageVO<PrjPrdPrpsFeeDetailVO>(feeList, feeList.size());
                pay.setPrjQuatPrpsPaySchPage(listPage);
            }
            if (CollectionUtils.isNotEmpty(pay.getFeeDetailList())) {
                List<PrjPrdPaySchDVO> list = new ArrayList<PrjPrdPaySchDVO>();
                for (PrjPrdPaySchDVO prjPrdPaySchDVO : pay.getFeeDetailList()) {
                    if (prjPrdPaySchDVO.getFeeClsCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_PRPS)) {
                        list.add(prjPrdPaySchDVO);
                    }
                }
                //首期款合计项
                PrjPrdPaySchDVO tatal = new PrjPrdPaySchDVO();
                tatal.setFeeTypCdNm("首期款合计");
                tatal.setFeeAmt(pay.getFirstPayAmt());
                tatal.setPaidUpAmt(pay.getTotalFirstPayAmt().longValue());
                list.add(tatal);
                feeListPage = new ListPageVO<PrjPrdPaySchDVO>(list, list.size());
                pay.setFeeDetailListPage(feeListPage);
            }
            if (CollectionUtils.isNotEmpty(pay.getSubFeeAmtTotalList())) {
                for (PrjPrdPaySchDVO paySchDVO : pay.getSubFeeAmtTotalList()) {
                    paySchDVO.setFeeAmt(DecimalUtils.convertFenToYuan(paySchDVO.getFeeAmt().longValue()));
                }
            }


            List<SysDictionaryVO> settFeeTypCdListJSON = this.prjPrdPaySchMService.getSettFeeTypList();

            view.addObject("pay", pay);
            view.addObject("cst", cst);
            view.addObject("prj", prj);
            view.addObject("dtl", dtl);
            view.addObject("settFeeTypCdListJSON", JSON.toJSONString(settFeeTypCdListJSON));
            view.addObject("subFeeAmtTotalList", JSON.toJSONString(pay.getSubFeeAmtTotalList()));
            view.addObject("listPage", JSON.toJSONString(listPage));
            view.addObject("feeListPage", JSON.toJSONString(feeListPage));
            view.addObject("paySchId", paySchId);
            view.addObject("zckcFlag", zckcFlag);
            view.addObject("model", "preview");// 代表结清申请预览
            return view;
        } catch (BaseException ex) {
            BaseLogUtils.info(logger, "showPreSettlePage", "显示提前结清详情页面查询失败.DATA:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
            throw ex;
        } catch (Exception ex) {
            BaseLogUtils.error(logger, "showPreSettlePage", "显示提前结清详情页面查询失败.DATA:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
            throw ex;
        }
    }


    /**
     * 显示提前结清添加费用项页面
     */
    @RequestMapping(value = "/zcCarPreSettleFlowPage.do", method = {RequestMethod.GET})
    public ModelAndView zcCarPreSettleFlowPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "preSettleFlowPage", "显示提前结清流程中详情页面.", CurrentThreadContext.getCurrentUserName());
        String paySchId = request.getParameter("paySchId");//支付表ID
        String isDetail_bk = request.getParameter("isDetail_bk");//标识是否详情_YAOXIURONG
        String showBk_oCIn = request.getParameter("showBk_oCIn");//加载我司收款账号维护页面
        String showBk_oCOut = request.getParameter("showBk_oCOut");//加载我司付款账号维护页面
        String editInto = request.getParameter("editInto");//我司付款_维护收款账号
        String editOut = request.getParameter("editOut");//我司付款_维护付款账号
        //如果为空 设置为1 使流程中每个节点都可以查看账户信息
        if (StringUtils.isEmpty(showBk_oCIn) && StringUtils.isEmpty(showBk_oCOut)) {
            showBk_oCIn = "1";
            showBk_oCOut = "1";
            isDetail_bk = "1";
        }

        String openTheBillAdd = request.getParameter("optba");//标识是否需要开票新增列表页面_FUJINGRUN
        String openTheBillForFinance = request.getParameter("optbf");//标识是否显示财务开票列表页面_FUJINGRUN
        String openTheBillForDetail = request.getParameter("optbd");//是否显示开票详细列表页面_FUJINGRUN
        String procInstId = request.getParameter("processInstanceId");//流程实例ID_FUJINGRUN
        Integer payPd = 0;//提前结清时结清期数
        PrjBscInfoVO prj = null;
        PrjPrdPaySchMVO pay = null;
        CstBscInfoVO cst = null;
        ListPageVO<PrjPrdPrpsFeeDetailVO> listPage = null;
        ListPageVO<PrjPrdPaySchDVO> feeListPage = null;
        PrjPrdDtlVO dtl = null;
        Date applyDate = null;
        double discountAmt = 0d;
        double breachAmt = 0d;
        ModelAndView view = new ModelAndView("project/prjPrdPaySchSett/prjPrdPaySchMPerSettleFlowPage");
        try {
            if (StringUtils.isNotBlank(paySchId)) {
                // 查找结清期数
                PrjPrdPaySchMVO schMVO = getSchMVO(procInstId, Long.valueOf(paySchId));
                payPd = schMVO.getStlPd();

                PrjStlMVO stlMVO = this.prjStlMService.selectByPaySchMId(Long.valueOf(paySchId), PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_CST);
                pay = this.prjPrdPaySchMService.searchPreSettleData(Long.valueOf(paySchId), null, Integer.valueOf(payPd));

                List<PrjPrdPaySchDVO> payFeeList = pay.getFeeDetailList();
                if (CollectionUtils.isNotEmpty(payFeeList)) {
                    for (PrjPrdPaySchDVO prjPrdPaySchDDTO : payFeeList) {
                        if (prjPrdPaySchDDTO.getFeeClsCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_SETT) && null != prjPrdPaySchDDTO.getIsSysDef() && prjPrdPaySchDDTO.getIsSysDef().equals(BaseConstant.IS_YESNO_YES)) {
                            if (prjPrdPaySchDDTO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_201)) {
                                discountAmt = prjPrdPaySchDDTO.getFeeAmt();
                            }
                            if (prjPrdPaySchDDTO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_103)) {
                                breachAmt = prjPrdPaySchDDTO.getFeeAmt();
                            }
                        }
                    }
                }
                // 申请时间
                applyDate = pay.getApplyDt();
                if (null != stlMVO && null != applyDate && null != stlMVO.getStlStDt()
                        && org.apache.commons.lang3.time.DateUtils.isSameDay(applyDate, stlMVO.getStlStDt())) {
                    if (null != stlMVO.getRmS03ArTotAmt()) {
                        pay.setLastPrintAmt(stlMVO.getRmS03ArTotAmt());
                    }
                    if (null != stlMVO.getRmS02ArTotAmt()) {
                        pay.setLastIntAmt(stlMVO.getRmS02ArTotAmt());
                    }
                    if (null != stlMVO.getRmS03CurrAmt()) {
                        pay.setCurrentPrintAmt(stlMVO.getRmS03CurrAmt());
                    }
                    if (null != stlMVO.getRmS02CurrAmt()) {
                        pay.setCurrentIntAmt(stlMVO.getRmS02CurrAmt());
                    }

                    if (null != stlMVO.getStlPenaltyAmt()) {
                        pay.setPenaltyAmt(stlMVO.getStlPenaltyAmt());
                    }
                    if (null != stlMVO.getStlOverdueAmt()) {
                        pay.setOverdueAmt(stlMVO.getStlOverdueAmt());
                    }
                    if (null != stlMVO.getStlAmt()) {
                        pay.setStlAmt(stlMVO.getStlAmt().longValue());
                        pay.setFinalPayAmt(stlMVO.getStlAmt());
                        pay.setTotalSettAmt(stlMVO.getStlAmt());
                    }
                }
                pay.setBreachAmt(breachAmt);
                pay.setDiscountAmt(discountAmt);
                PrjPrdDtlQueryCondition qc = new PrjPrdDtlQueryCondition();
                qc.setPaySchId(Long.valueOf(paySchId));
                List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(qc);
                if (CollectionUtils.isNotEmpty(dtlList)) {
                    dtl = dtlList.get(0);
                }
                if (null != pay) {
                    cst = this.cstBscInfoService.selectDetailById(pay.getCstId());
                    prj = this.prjBscInfoService.selectById(pay.getPrjId());
                }

                if (CollectionUtils.isNotEmpty(pay.getPrjPrdPayDetailList())) {
                    List<PrjPrdPrpsFeeDetailVO> feeList = null;
                    double totalRnt = 0d;//租金
                    double totalPrint = 0d;//本金
                    double totalInt = 0d;//利息

                    if (payPd != 0) {
                        //查询流程中临时状态的期数
                        Integer payPdFlow = null;
                        List<PrjPrdPaySchDVO> list = this.prjPrdPaySchDService.selectPaySchByDelStatusAndPaySchId(Long.valueOf(paySchId), PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                        if (CollectionUtils.isNotEmpty(list)) {
                            payPdFlow = list.get(0).getPayPd();
                            feeList = new ArrayList<PrjPrdPrpsFeeDetailVO>();
                            for (PrjPrdPrpsFeeDetailVO payDetail : pay.getPrjPrdPayDetailList()) {
                                if (payDetail.getPayPd().intValue() < Integer.valueOf(payPdFlow).intValue()) {
                                    totalRnt = DecimalUtils.add(totalRnt, payDetail.getRntAmt());
                                    totalPrint = DecimalUtils.add(totalPrint, payDetail.getPrinAmt());
                                    totalInt = DecimalUtils.add(totalInt, payDetail.getIntAmt());
                                    feeList.add(payDetail);
                                }
                                if (null != stlMVO) {
                                    if (payDetail.getPayPd().intValue() == Integer.valueOf(payPdFlow).intValue()) {
                                        payDetail.setRntAmt(stlMVO.getRmS01ArTotAmt());
                                        payDetail.setPrinAmt(stlMVO.getRmS03ArTotAmt());
                                        payDetail.setIntAmt(stlMVO.getRmS02ArTotAmt());
                                        payDetail.setRemPrinAmt(0d);
                                        payDetail.setIsDel(PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                                        feeList.add(payDetail);
                                    }
                                } else {
                                    if (payDetail.getPayPd().intValue() == Integer.valueOf(payPdFlow).intValue()) {
                                        payDetail.setRntAmt(DecimalUtils.sub(pay.getTotalRntAmt(), totalRnt));
                                        payDetail.setPrinAmt(DecimalUtils.sub(pay.getTotalPrinAmt(), totalPrint));
                                        payDetail.setIntAmt(DecimalUtils.sub(pay.getTotalIntAmt(), totalInt));
                                        payDetail.setRemPrinAmt(0d);
                                        payDetail.setIsDel(PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                                        feeList.add(payDetail);
                                    }
                                }
                            }

                        } else {
                            //payPdFlow = payPd;
                            feeList = pay.getPrjPrdPayDetailList();
                        }

                    } else {
                        feeList = pay.getPrjPrdPayDetailList();
                    }
                    listPage = new ListPageVO<PrjPrdPrpsFeeDetailVO>(feeList, feeList.size());
                    pay.setPrjQuatPrpsPaySchPage(listPage);
                }

                if (CollectionUtils.isNotEmpty(pay.getFeeDetailList())) {
                    List<PrjPrdPaySchDVO> list = new ArrayList<PrjPrdPaySchDVO>();
                    for (PrjPrdPaySchDVO prjPrdPaySchDVO : pay.getFeeDetailList()) {
                        if (prjPrdPaySchDVO.getFeeClsCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_PRPS)) {
                            list.add(prjPrdPaySchDVO);
                        }
                    }
                    //首期款合计项
                    PrjPrdPaySchDVO tatal = new PrjPrdPaySchDVO();
                    tatal.setFeeTypCdNm("首期款合计");
                    tatal.setFeeAmt(pay.getFirstPayAmt());
                    tatal.setPaidUpAmt(pay.getTotalFirstPayAmt().longValue());
                    list.add(tatal);
                    feeListPage = new ListPageVO<PrjPrdPaySchDVO>(list, list.size());
                    pay.setFeeDetailListPage(feeListPage);
                }
                if (CollectionUtils.isNotEmpty(pay.getSubFeeAmtTotalList())) {
                    for (PrjPrdPaySchDVO paySchDVO : pay.getSubFeeAmtTotalList()) {
                        paySchDVO.setFeeAmt(DecimalUtils.convertFenToYuan(paySchDVO.getFeeAmt().longValue()));
                    }
                }
            }

            List<SysDictionaryVO> settFeeTypCdListJSON = this.prjPrdPaySchMService.getSettFeeTypList();
            //费用类型

            view.addObject("pay", pay);
            view.addObject("cst", cst);
            view.addObject("prj", prj);
            view.addObject("dtl", dtl);
            view.addObject("showBk_oCIn", showBk_oCIn);
            view.addObject("isDetail_bk", isDetail_bk);
            view.addObject("showBk_oCOut", showBk_oCOut);
            view.addObject("editInto", editInto);
            view.addObject("editOut", editOut);
            view.addObject("subFeeAmtTotalList", JSON.toJSONString(pay.getSubFeeAmtTotalList()));
            view.addObject("listPage", JSON.toJSONString(listPage));
            view.addObject("feeListPage", JSON.toJSONString(feeListPage));
            view.addObject("paySchId", paySchId);
            view.addObject("settFeeTypCdListJSON", JSON.toJSONString(settFeeTypCdListJSON));
            view.addObject("optba", openTheBillAdd);
            view.addObject("optbf", openTheBillForFinance);
            view.addObject("optbd", openTheBillForDetail);
            view.addObject("procInstId", procInstId);
            view.addObject("fileAuth", request.getParameter("fileAuth"));
        } catch (BaseException ex) {
            BaseLogUtils.info(logger, "preSettleFlowPage", "结清流程中页面查询失败.DATA:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
        } catch (Exception ex) {
            BaseLogUtils.error(logger, "preSettleFlowPage", "结清流程中页面查询失败.DATA:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
        }
        return view;
    }

    /**
     * 显示分解之前的结清数据
     */
    @RequestMapping(value = "/searchZCCarBeforeSplitPreSettleData.do", method = {RequestMethod.GET})
    public ModelAndView searchZCCarBeforeSplitPreSettleData(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "newPreSettleFlowPage", "显示提前结清流程中详情页面.", CurrentThreadContext.getCurrentUserName());
        String paySchId = request.getParameter("paySchId");//支付表ID
        String isDetail_bk = request.getParameter("isDetail_bk");//标识是否详情_YAOXIURONG
        String showBk_oCIn = request.getParameter("showBk_oCIn");//加载我司收款账号维护页面
        String showBk_oCOut = request.getParameter("showBk_oCOut");//加载我司付款账号维护页面
        String editInto = request.getParameter("editInto");//我司付款_维护收款账号
        String editOut = request.getParameter("editOut");//我司付款_维护付款账号
        ModelAndView view = new ModelAndView("project/prjPrdPaySchSett/prjPrdPaySchMPreSplitSettlePage");
        String openTheBillAdd = request.getParameter("optba");//标识是否需要开票新增列表页面_FUJINGRUN
        String openTheBillForFinance = request.getParameter("optbf");//标识是否显示财务开票列表页面_FUJINGRUN
        String openTheBillForDetail = request.getParameter("optbd");//是否显示开票详细列表页面_FUJINGRUN
        String procInstId = request.getParameter("processInstanceId");//流程实例ID_FUJINGRUN
        Integer payPd = 0;//提前结清时结清期数
        PrjBscInfoVO prj = null;
        PrjPrdPaySchMVO pay = null;
        CstBscInfoVO cst = null;
        ListPageVO<PrjPrdPrpsFeeDetailVO> listPage = null;
        ListPageVO<PrjPrdPaySchDVO> feeListPage = null;
        PrjPrdDtlVO dtl = null;
        Date applyDate = null;
        try {
            if (StringUtils.isNotBlank(paySchId)) {
                // 查找结清期数
                PrjPrdPaySchMVO schMVO = getSchMVO(procInstId, Long.valueOf(paySchId));
                payPd = schMVO.getStlPd();

                PrjStlMVO prjStlMVO = this.prjStlMService.selectByPaySchMId(Long.valueOf(paySchId), PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_CST);
                if (null == prjStlMVO) {
                    pay = this.prjPrdPaySchMService.searchPreSettleData(Long.valueOf(paySchId), null, Integer.valueOf(payPd));
                } else {
                    pay = this.prjPrdPaySchMService.searchSettleDataForFlow(Long.valueOf(paySchId), null, Integer.valueOf(payPd));
                }
                PrjPrdDtlQueryCondition qc = new PrjPrdDtlQueryCondition();
                qc.setPaySchId(Long.valueOf(paySchId));
                List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(qc);
                if (CollectionUtils.isNotEmpty(dtlList)) {
                    dtl = dtlList.get(0);
                }
                if (null != pay) {
                    cst = this.cstBscInfoService.selectDetailById(pay.getCstId());
                    prj = this.prjBscInfoService.selectById(pay.getPrjId());
                }

                if (CollectionUtils.isNotEmpty(pay.getPrjPrdPayDetailList())) {
                    List<PrjPrdPrpsFeeDetailVO> feeList = null;
                    double totalRnt = 0d;//租金
                    double totalPrint = 0d;//本金
                    double totalInt = 0d;//利息
                    if (payPd != 0) {
                        //查询流程中临时状态的期数
                        Integer payPdFlow = null;
                        List<PrjPrdPaySchDVO> list = this.prjPrdPaySchDService.selectPaySchByDelStatusAndPaySchId(Long.valueOf(paySchId), PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                        if (CollectionUtils.isNotEmpty(list)) {
                            payPdFlow = list.get(0).getPayPd();
                            feeList = new ArrayList<PrjPrdPrpsFeeDetailVO>();
                            for (PrjPrdPrpsFeeDetailVO payDetail : pay.getPrjPrdPayDetailList()) {
                                if (payDetail.getPayPd().intValue() < Integer.valueOf(payPdFlow).intValue()) {
                                    totalRnt = DecimalUtils.add(totalRnt, payDetail.getRntAmt());
                                    totalPrint = DecimalUtils.add(totalPrint, payDetail.getPrinAmt());
                                    totalInt = DecimalUtils.add(totalInt, payDetail.getIntAmt());
                                    feeList.add(payDetail);
                                }
                                if (payDetail.getPayPd().intValue() == Integer.valueOf(payPdFlow).intValue()) {
                                    if (null != prjStlMVO) {
                                        payDetail.setRntAmt(prjStlMVO.getRmS01ArTotAmt());
                                        payDetail.setPrinAmt(prjStlMVO.getRmS03ArTotAmt());
                                        payDetail.setIntAmt(prjStlMVO.getRmS02ArTotAmt());
                                        payDetail.setRemPrinAmt(0d);
                                        payDetail.setIsDel(PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                                    } else {
                                        payDetail.setRntAmt(DecimalUtils.sub(pay.getTotalRntAmt(), totalRnt));
                                        payDetail.setPrinAmt(DecimalUtils.sub(pay.getTotalPrinAmt(), totalPrint));
                                        payDetail.setIntAmt(DecimalUtils.sub(pay.getTotalIntAmt(), totalInt));
                                        payDetail.setRemPrinAmt(0d);
                                        payDetail.setIsDel(PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                                    }
                                    feeList.add(payDetail);
                                }
                            }

                        } else {
                            //payPdFlow = payPd;
                            feeList = pay.getPrjPrdPayDetailList();
                        }

                    } else {
                        feeList = pay.getPrjPrdPayDetailList();
                    }
                    listPage = new ListPageVO<PrjPrdPrpsFeeDetailVO>(feeList, feeList.size());
                    pay.setPrjQuatPrpsPaySchPage(listPage);
                }

                if (CollectionUtils.isNotEmpty(pay.getFeeDetailList())) {
                    List<PrjPrdPaySchDVO> list = new ArrayList<PrjPrdPaySchDVO>();
                    for (PrjPrdPaySchDVO prjPrdPaySchDVO : pay.getFeeDetailList()) {
                        if (prjPrdPaySchDVO.getFeeClsCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_PRPS)) {
                            list.add(prjPrdPaySchDVO);
                        }
                    }
                    //首期款合计项
                    PrjPrdPaySchDVO tatal = new PrjPrdPaySchDVO();
                    tatal.setFeeTypCdNm("首期款合计");
                    tatal.setFeeAmt(pay.getFirstPayAmt());
                    tatal.setPaidUpAmt(pay.getTotalFirstPayAmt().longValue());
                    list.add(tatal);
                    feeListPage = new ListPageVO<PrjPrdPaySchDVO>(list, list.size());
                    pay.setFeeDetailListPage(feeListPage);
                }
                if (CollectionUtils.isNotEmpty(pay.getSubFeeAmtTotalList())) {
                    for (PrjPrdPaySchDVO paySchDVO : pay.getSubFeeAmtTotalList()) {
                        paySchDVO.setFeeAmt(DecimalUtils.convertFenToYuan(paySchDVO.getFeeAmt().longValue()));
                    }
                }

            }

            List<SysDictionaryVO> settFeeTypCdListJSON = this.prjPrdPaySchMService.getSettFeeTypList();
            //费用类型

            view.addObject("pay", pay);
            view.addObject("cst", cst);
            view.addObject("prj", prj);
            view.addObject("dtl", dtl);
            view.addObject("showBk_oCIn", showBk_oCIn);
            view.addObject("isDetail_bk", isDetail_bk);
            view.addObject("showBk_oCOut", showBk_oCOut);
            view.addObject("editInto", editInto);
            view.addObject("editOut", editOut);
            view.addObject("subFeeAmtTotalList", JSON.toJSONString(null == pay.getSubFeeAmtTotalList() ? "" : pay.getSubFeeAmtTotalList()));
            view.addObject("listPage", JSON.toJSONString(listPage));
            view.addObject("feeListPage", JSON.toJSONString(feeListPage));
            view.addObject("paySchId", paySchId);
            view.addObject("settFeeTypCdListJSON", JSON.toJSONString(settFeeTypCdListJSON));
            view.addObject("optba", openTheBillAdd);
            view.addObject("optbf", openTheBillForFinance);
            view.addObject("optbd", openTheBillForDetail);
            view.addObject("procInstId", procInstId);

        } catch (BaseException ex) {
            BaseLogUtils.info(logger, "preSettleFlowPage", "结清流程中页面查询失败.DATA:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
        } catch (Exception ex) {
            BaseLogUtils.error(logger, "preSettleFlowPage", "结清流程中页面查询失败.DATA:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
        }
        return view;
    }


    /**
     * 新增
     */
    @RequestMapping(value = "/dealExceptionData.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object dealExceptionData(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO resultVO = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
        String id = request.getParameter("id");//支付表ID
        PrjBscInfoVO prj = null;
        PrjPrdPaySchMVO pay = null;
        CstBscInfoVO cst = null;
        ListPageVO<PrjPrdPrpsFeeDetailVO> listPage = null;
        ListPageVO<PrjPrdPaySchDVO> feeListPage = null;
        PrjPrdDtlVO dtl = null;
        Integer actPayPd = null;//实际还到的期数
        Integer payPd = null;//期数
        Date applyDate = null;
        List<PrjPrdPrpsFeeDetailVO> feeList = null;
        feeList = new ArrayList<PrjPrdPrpsFeeDetailVO>();
        try {
            pay = this.prjPrdPaySchMService.selectPrjPrdPaySchMAndDetailById(Long.valueOf(id));
            if (CollectionUtils.isNotEmpty(pay.getPrjPrdPayDetailList())) {
                double totalRnt = 0d;//租金
                double totalPrint = 0d;//本金
                double totalInt = 0d;//利息
                double actTotalRnt = 0d;//实际剩余租金
                double actTotalPrint = 0d;//实际本金
                double actTotalInt = 0d;//实际利息
                if (null == payPd) {
                    //查找流程发起时的期数
                    SysFlowSHQueryCondition flowQc = new SysFlowSHQueryCondition();
                    List<Long> idList = new ArrayList<Long>();
                    idList.add(Long.valueOf(id));
                    flowQc.setDataIdList(idList);
                    flowQc.setWordsInTheTable(PrjBscInfoConstant.PRJ_FLOW_S_H_PRJ);
                    flowQc.setSysCd(CurrentThreadContext.getCurrentSysCd());
                    flowQc.setStatus(BaseConstant.IS_YESNO_YES);
                    List<String> busTypList = new ArrayList<String>();
                    busTypList.add(FlowConstant.FLOW_MODEL_TYP_SETTLE_NORMAL);
                    busTypList.add(FlowConstant.FLOW_MODEL_TYP_SETTLE_ADVANCE);
                    flowQc.setBusTypList(busTypList);
                    List<SysFlowSHDTO> flowSHList = this.flowQueryApiService.searchFlowSHList(flowQc);
                    if (CollectionUtils.isNotEmpty(flowSHList)) {
                        applyDate = flowSHList.get(0).getpCrtTm();
                    }

                    PrjPrdPaySchDQueryCondition payQc = new PrjPrdPaySchDQueryCondition();
                    payQc.setPaySchId(Long.valueOf(id));
                    payQc.setSortName("PAY_PD");
                    payQc.setSortOrder("ASC");
                    payQc.setCurrentDt(applyDate);
                    payQc.setFeeTypCd(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_RNT_PRICE);
                    List<PrjPrdPaySchDVO> payList = this.prjPrdPaySchDService.searchList(payQc);
                    if (CollectionUtils.isNotEmpty(payList)) {
                        payPd = payList.get(0).getPayPd();
                    } else {
                        payPd = 0;
                    }
                }

                if (null != payPd) {
                    //	feeList = new ArrayList<PrjPrdPrpsFeeDetailVO>();
                    //查找实际已经还的期数，如果期数大于当前选择的期数
                    for (PrjPrdPaySchDVO prjPrdPaySchDVO : pay.getPrjPrdPaySchDList()) {
                        if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_RNT_PRICE)) {
                            if (null == prjPrdPaySchDVO.getPaidUpAmt() || prjPrdPaySchDVO.getFeeAmt().longValue() != prjPrdPaySchDVO.getPaidUpAmt()) {
                                actPayPd = prjPrdPaySchDVO.getPayPd();
                                break;
                            }
                        }
                    }

                    for (PrjPrdPaySchDVO prjPrdPaySchDVO : pay.getPrjPrdPaySchDList()) {
                        if (null != actPayPd && prjPrdPaySchDVO.getPayPd() >= actPayPd) {
                            double arAmt = DecimalUtils.convertFenToYuan(prjPrdPaySchDVO.getArAmt());
                            if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_RNT_PRICE)) {
                                actTotalRnt = DecimalUtils.add(actTotalRnt, arAmt);
                            }
                            if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_PRINT_PRICE)) {
                                actTotalPrint = DecimalUtils.add(actTotalPrint, arAmt);
                            }
                            if (prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_INT_PRICE)) {
                                actTotalInt = DecimalUtils.add(actTotalInt, arAmt);
                            }
                        }
                    }


                    for (PrjPrdPrpsFeeDetailVO payDetail : pay.getPrjPrdPayDetailList()) {
                        if (actPayPd < payPd) {
                            if (payDetail.getPayPd().intValue() < Integer.valueOf(payPd).intValue()) {
                                totalRnt = DecimalUtils.add(totalRnt, payDetail.getRntAmt());
                                totalPrint = DecimalUtils.add(totalPrint, payDetail.getPrinAmt());
                                totalInt = DecimalUtils.add(totalInt, payDetail.getIntAmt());
                                feeList.add(payDetail);
                            }
                            if (payDetail.getPayPd().intValue() == Integer.valueOf(payPd).intValue()) {
                                payDetail.setRntAmt(DecimalUtils.sub(pay.getTotalRntAmt(), totalRnt));
                                payDetail.setPrinAmt(DecimalUtils.sub(pay.getTotalPrinAmt(), totalPrint));
                                payDetail.setIntAmt(DecimalUtils.sub(pay.getTotalIntAmt(), totalInt));
                                payDetail.setRemPrinAmt(0d);
                                payDetail.setIsDel(PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                                feeList.add(payDetail);
                            }
                        } else {
                            if (payDetail.getPayPd().intValue() < Integer.valueOf(actPayPd).intValue()) {
                                totalRnt = DecimalUtils.add(totalRnt, payDetail.getRntAmt());
                                totalPrint = DecimalUtils.add(totalPrint, payDetail.getPrinAmt());
                                totalInt = DecimalUtils.add(totalInt, payDetail.getIntAmt());
                                feeList.add(payDetail);
                            }
                            if (payDetail.getPayPd().intValue() == Integer.valueOf(actPayPd).intValue()) {
                                //提前还款剩余的期次为支付表实际剩余的租金、本金、利息
                                payDetail.setRntAmt(actTotalRnt);
                                payDetail.setPrinAmt(actTotalPrint);
                                payDetail.setIntAmt(actTotalInt);
                                payDetail.setRemPrinAmt(0d);
                                payDetail.setIsDel(PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                                feeList.add(payDetail);
                            }
                        }
                    }
                } else {
                    feeList = pay.getPrjPrdPayDetailList();
                }
                listPage = new ListPageVO<PrjPrdPrpsFeeDetailVO>(feeList, feeList.size());
                pay.setPrjQuatPrpsPaySchPage(listPage);
            }
            if (CollectionUtils.isNotEmpty(pay.getFeeDetailList())) {
                List<PrjPrdPaySchDVO> list = new ArrayList<PrjPrdPaySchDVO>();
                for (PrjPrdPaySchDVO prjPrdPaySchDVO : pay.getFeeDetailList()) {
                    if (prjPrdPaySchDVO.getFeeClsCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_PRPS)) {
                        list.add(prjPrdPaySchDVO);
                    }

                }


                feeListPage = new ListPageVO<PrjPrdPaySchDVO>(list, list.size());
                pay.setFeeDetailListPage(feeListPage);
            }
            if (CollectionUtils.isNotEmpty(pay.getSubFeeAmtTotalList())) {
                for (PrjPrdPaySchDVO paySchDVO : pay.getSubFeeAmtTotalList()) {
                    paySchDVO.setFeeAmt(DecimalUtils.convertFenToYuan(paySchDVO.getFeeAmt().longValue()));

                }
            }
            List<PrjPrdPaySchDVO> prjPrdPaySchDList = new ArrayList<PrjPrdPaySchDVO>();
            for (PrjPrdPrpsFeeDetailVO payDetail : feeList) {
                PrjPrdPaySchDVO intPay = new PrjPrdPaySchDVO();
                intPay.setFeeAmt(DecimalUtils.convertYuanToFen(payDetail.getIntAmt()).doubleValue());
                intPay.setArAmt(DecimalUtils.convertYuanToFen(payDetail.getIntAmt()));
                intPay.setPayDt(payDetail.getPayDt());
                intPay.setPaySchId(Long.valueOf(id));
                intPay.setCrtTm(new Date());
                intPay.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
                intPay.setFeeTypCd(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_INT_PRICE);
                intPay.setPayPd(payDetail.getPayPd());
                intPay.setMdfTm(new Date());
                intPay.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
                intPay.setCapFlow(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CASH_FLOW_IN);
                intPay.setIsDel(PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                PrjPrdPaySchDVO prinPay = new PrjPrdPaySchDVO();
                prinPay.setFeeAmt(DecimalUtils.convertYuanToFen(payDetail.getPrinAmt()).doubleValue());
                prinPay.setArAmt(DecimalUtils.convertYuanToFen(payDetail.getPrinAmt()));
                prinPay.setPayDt(payDetail.getPayDt());
                prinPay.setPaySchId(Long.valueOf(id));
                prinPay.setCrtTm(new Date());
                prinPay.setPayPd(payDetail.getPayPd());
                prinPay.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
                prinPay.setFeeTypCd(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_PRINT_PRICE);
                prinPay.setMdfTm(new Date());
                prinPay.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
                prinPay.setCapFlow(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CASH_FLOW_IN);
                prinPay.setIsDel(PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                PrjPrdPaySchDVO remPrinPay = new PrjPrdPaySchDVO();
                remPrinPay.setArAmt(DecimalUtils.convertYuanToFen(payDetail.getRemPrinAmt()));
                remPrinPay.setPayDt(payDetail.getPayDt());
                remPrinPay.setPaySchId(Long.valueOf(id));
                remPrinPay.setFeeAmt(DecimalUtils.convertYuanToFen(payDetail.getRemPrinAmt()).doubleValue());
                remPrinPay.setPayPd(payDetail.getPayPd());
                remPrinPay.setCrtTm(new Date());
                remPrinPay.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
                remPrinPay.setFeeTypCd(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_REMPRIN_PRICE);
                remPrinPay.setMdfTm(new Date());
                remPrinPay.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
                remPrinPay.setCapFlow(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CASH_FLOW_IN);
                remPrinPay.setIsDel(PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);

                PrjPrdPaySchDVO rntPay = new PrjPrdPaySchDVO();
                rntPay.setArAmt(DecimalUtils.convertYuanToFen(payDetail.getRntAmt()));
                rntPay.setPayDt(payDetail.getPayDt());
                rntPay.setPaySchId(Long.valueOf(id));
                rntPay.setFeeAmt(DecimalUtils.convertYuanToFen(payDetail.getRntAmt()).doubleValue());
                rntPay.setPayPd(payDetail.getPayPd());
                rntPay.setCrtTm(new Date());
                rntPay.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
                rntPay.setFeeTypCd(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_RNT_PRICE);
                rntPay.setMdfTm(new Date());
                rntPay.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
                rntPay.setCapFlow(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CASH_FLOW_IN);
                rntPay.setIsDel(PrjPrdPaySchDConstant.PRJ_PRD_PAY_FEE_FLOW_SAVE_STATUS);
                prjPrdPaySchDList.add(rntPay);
                prjPrdPaySchDList.add(intPay);
                prjPrdPaySchDList.add(prinPay);
                prjPrdPaySchDList.add(remPrinPay);
            }
            pay.setPrjPrdPaySchDList(prjPrdPaySchDList);

            BaseLogUtils.info(logger, "addPrjPrdPayRickDep", "保存风险保证金数据成功," + ".DATA:" + JSONObject.toJSONString(id), CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            resultVO = new DataResultVO();
            resultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            resultVO.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.info(logger, "addPrjPrdPayRickDep", "保存风险保证金数据失败.DATA:" + JSONObject.toJSONString(id) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            resultVO = new DataResultVO();
            resultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            resultVO.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.error(logger, "addPrjPrdPayRickDep", "保存风险保证金数据失败,系统错误.DATA:" + JSONObject.toJSONString(id) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return resultVO;
    }

    /**
     *
     */
    @RequestMapping(value = "/getTotalRntAmtByPayPd.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object getTotalRntAmtByPayPd(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
        PrjPrdPaySchMVO pay = null;//获取参数
        String prjPrdSchId = request.getParameter("paySchId");
        String reduStartPd = request.getParameter("reduStartLsPd");
        DataResultVO resultVO = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
        double afterPayPdLastRntAmt = 0d;
        try {
            PrjPrdPaySchMVO prjPrdPaySchMVO = this.prjPrdPaySchMService.selectPrjPrdPaySchMAndDetailById(Long.valueOf(prjPrdSchId));

            for (PrjPrdPrpsFeeDetailVO detail : prjPrdPaySchMVO.getPrjPrdPayDetailList()) {
                //以租代购页面选择期数之后的租金
                if (detail.getPayPd().intValue() >= Integer.valueOf(reduStartPd)) {
                    afterPayPdLastRntAmt = DecimalUtils.add(afterPayPdLastRntAmt, detail.getRntAmt());
                }
            }
            resultVO.setData(afterPayPdLastRntAmt);
            BaseLogUtils.info(logger, "getTotalRntAmtByPayPd", "发起提前结清流程成功," + ".DATA:" + JSONObject.toJSONString(pay), CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            resultVO = new DataResultVO();
            resultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            resultVO.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.info(logger, "getTotalRntAmtByPayPd", "发起提前结清流程失败.DATA:" + JSONObject.toJSONString(pay) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
            return resultVO;
        } catch (Exception ex) {
            resultVO = new DataResultVO();
            resultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            resultVO.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.error(logger, "getTotalRntAmtByPayPd", "发起提前结清流程失败,系统错误.DATA:" + JSONObject.toJSONString(pay) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
            return resultVO;
        }
        return resultVO;
    }

    /**
     * 保存使用金额
     * @param request
     * @param response
     * @return
     * @throws BaseException
     */
    @RequestMapping(value = "/addUseAmt.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object addUseAmt(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
        CapBindLogVO vo = new CapBindLogVO();
        CapBindLogQC qc = new CapBindLogQC();
        try {
            String paySchId = request.getParameter("paySchId");//支付表id
            String fundId = request.getParameter("id");//资金id
            String procInstId = request.getParameter("procInstId");//流程实例id
            String useAmts = request.getParameter("useAmts");//使用金额
            if (StringUtils.isNotBlank(useAmts)) {
                vo.setUseAmt(DecimalUtils.convertYuanToFen(Double.valueOf(useAmts)));
            }
            if (StringUtils.isNotBlank(paySchId)) {
                vo.setBizId(Long.valueOf(paySchId));
                qc.setBizId(Long.valueOf(paySchId));

            }
            if (StringUtils.isNotBlank(fundId)) {
                vo.setFundId(Long.valueOf(fundId));
                qc.setFundId(Long.valueOf(fundId));
            }
            if (StringUtils.isNotBlank(procInstId)) {
                vo.setProcInstId(procInstId);
            }
            CapFundVO capFundVO = this.capFundService.selectById(Long.valueOf(fundId));
            if (vo.getUseAmt()>capFundVO.getAvailableAmount()) {
                result.setSuccess(2);
                BaseLogUtils.info(logger, "addUseAmt", "使用金额大于可用金额, .DATA:" +"使用金额"+ JSONObject.toJSONString(vo.getUseAmt()), CurrentThreadContext.getCurrentUserName());
            }else {
                vo.setIsDel(0);
                vo.setIsValid(1);
                vo.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
                List<CapBindLogVO> capBindLogVOList = this.capBindLogService.searchList(qc);
                if (CollectionUtils.isNotEmpty(capBindLogVOList)) {
                    for (CapBindLogVO capBindLogVO : capBindLogVOList) {
                        vo.setId(capBindLogVO.getId());
                    }
                    Boolean flag = this.capBindLogService.modify(vo);
                    if (flag != true) {
                        result.setSuccess(BaseConstant.IS_YESNO_NO);
                        BaseLogUtils.info(logger, "addUseAmt", "修改capBindLod数据失败, .DATA:" + JSONObject.toJSONString(vo), CurrentThreadContext.getCurrentUserName());
                    }else {
                        BaseLogUtils.info(logger, "addUseAmt", "修改capBindLod数据成功, .DATA:" + JSONObject.toJSONString(vo), CurrentThreadContext.getCurrentUserName());
                    }
                }else {
                    vo.setCrtTm(new Date());
                    Long id = this.capBindLogService.add(vo);
                    BaseLogUtils.info(logger, "addUseAmt", "新增capBindLod数据成功, .id:" + JSONObject.toJSONString(id), CurrentThreadContext.getCurrentUserName());
                }
            }
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.info(logger, "addUseAmt", "新增capBindLod数据失败.DATA:" + JSONObject.toJSONString(vo) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.error(logger, "addUseAmt", "新增capBindLod数据失败,系统错误.DATA:" + JSONObject.toJSONString(vo) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }
    /**
     * 导出支付表信息
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/exportPrjPrdPaySchNew.do", method = {RequestMethod.POST})
    @ResponseBody
    public DataResultVO exportPrjPrdPaySchNew(HttpServletRequest request, HttpServletResponse response) {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
        String id = request.getParameter("id");//支付表ID
        try {
            if (StringUtils.isNotBlank(id)) {
                result = this.prjPrdPaySchMService.exportPrjPrdPaySchExcelDataNew(Long.valueOf(id));
            }
            BaseLogUtils.info(logger, "exportPrjPrdPaySch", "导出支付表数据.[paySchId=" + id + "]", CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "exportPrjPrdPaySch", "导出支付表失败.[paySchId=" + id + "]" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "exportPrjPrdPaySch", "导出支付表失败.[paySchId=" + id + "]" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }


    /**
     * 起租通知书
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/exportRentNoticeNew.do", method = {RequestMethod.POST})
    @ResponseBody
    public DataResultVO exportRentNoticeNew(HttpServletRequest request, HttpServletResponse response) {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
        String id = request.getParameter("id");//支付表ID
        try {
            if (StringUtils.isNotBlank(id)) {
                result = this.prjPrdPaySchMService.exportRentNoticeNew(Long.valueOf(id));
            }
            BaseLogUtils.info(logger, "exportRentNotice", "导出起租通知书数据.[paySchId=" + id + "]", CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "exportRentNotice", "导出起租通知书数据失败.[paySchId=" + id + "]" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "exportRentNotice", "导出起租通知书据失败.[paySchId=" + id + "]" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }


    /**
     * 支付表首期款明细表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/exportFirstPayAmtNew.do", method = {RequestMethod.POST})
    @ResponseBody
    public DataResultVO exportFirstPayAmtNew(HttpServletRequest request, HttpServletResponse response) {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
        String id = request.getParameter("id");//支付表ID
        try {
            if (StringUtils.isNotBlank(id)) {
                result = this.prjPrdPaySchMService.exportFirstPayAmtNew(Long.valueOf(id));
            }
            BaseLogUtils.info(logger, "exportFirstPayAmt", "导出支付表首期款明细表数据.[paySchId=" + id + "]", CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "exportFirstPayAmt", "导出支付表首期款明细表失败.[paySchId=" + id + "]" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "exportFirstPayAmt", "导出支付表首期款明细表失败.[paySchId=" + id + "]" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }


    /**
     * 到厂商新增页面
     */
    @RequestMapping(value = "/toMfrAddPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toMfrAddPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toAddPage", "加载PrjPrdPaySchM Add页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView mav = new ModelAndView("project/prjprdquatprps/prjMfrPrdQuatPrpsAdd");
        String prjPrdDtlId = request.getParameter("prjPrdDtlId");//项目商品明细ID
        String prjId = request.getParameter("prjId");//项目ID
        String prjPrdId = request.getParameter("prjPrdId");
        String id = request.getParameter("id");
        String detailFlag = request.getParameter("detailFlag");
        //费用类型
        JSONArray feeTypCdListJSON = this.prjQuatPrpsCfgMService.searchFeeTypCdList();
        mav.addObject("feeTypCdListJSON", feeTypCdListJSON);
        //费用计算基数
        List<KeyValueVO> calBaseCdList = this.prjQuatPrpsCfgMService.searchCalBaseCdList();
        if (CollectionUtils.isNotEmpty(calBaseCdList)) {
            for (int i = 0; i < calBaseCdList.size(); i++) {
                if (calBaseCdList.get(i).getKey().equals(PrjQuatPrpsConstant.CODE_CAL_BASE_CONTRACT)) {
                    calBaseCdList.remove(i);
                }
            }
        }
        mav.addObject("calBaseCdListJSON", JSON.toJSONString(calBaseCdList));
        List<KeyValueVO> yesNoCdList = this.prjQuatPrpsCfgMService.searchYesOrNoCdList();
        mav.addObject("yesOrNoCdListJSON", JSON.toJSONString(yesNoCdList));
        //费用计入方式
        List<KeyValueVO> cntWayCdList = this.prjQuatPrpsCfgMService.searchCntWayCdList();
        Map<String, String> scaleNumMap = this.prjQuatPrpsService.getDecimalDigitsByBuOrgCode();
        if (CollectionUtils.isNotEmpty(cntWayCdList)) {
            for (int i = 0; i < cntWayCdList.size(); i++) {
                if (cntWayCdList.get(i).getKey().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_FINANC)) {
                    cntWayCdList.remove(i);
                }
            }
        }

        PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(Long.valueOf(prjId));
        //计算方式
        mav.addObject("cntWayCdListJSON", JSON.toJSONString(cntWayCdList));
        mav.addObject("prjId", prjId);
        mav.addObject("prjPrdDtlId", prjPrdDtlId);
        mav.addObject("prjPrdId", prjPrdId);
        mav.addObject("id", id);
        mav.addObject("detailFlag", detailFlag);
        mav.addObject("insCode", null == prjBscInfoVO.getInsCode() ? "" : prjBscInfoVO.getInsCode());
        mav.addObject("scaleNumMap", scaleNumMap.isEmpty() == true ? "" : JSON.toJSONString(scaleNumMap));
        return mav;
    }

    /**
     * 得到一条记录
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getMfrById.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object getMfrById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String id = request.getParameter("id");
        String prjId = request.getParameter("prjId");
        String prjPrdId = request.getParameter("prjPrdId");
        String prjPrdDtlId = request.getParameter("prjPrdDtlId");
        if (StringUtils.isNotBlank(prjPrdDtlId) && StringUtils.isBlank(prjPrdId)) {
            PrjPrdDtlVO vo = prjPrdDtlService.selectById(Long.valueOf(prjPrdDtlId));
            if (vo != null) {
                prjPrdId = String.valueOf(vo.getPrjPrdId());
            }
        }
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        PrjMfrPrdPaySchMVO vo = null;
        PrjQuatPrpsCfgMVO quatPrps = null;
        try {
            vo = this.prjPrdPaySchMService.selectPrjMfrPrdPaySchMAndDetailById(Long.valueOf(id));
            if (null == vo) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
                BaseLogUtils.info(logger, "getMfrById", "获取PrjPrdPaySchM数据不存在,ID:" + id, CurrentThreadContext.getCurrentUserName());
            }
            PrjBscInfoVO prjBsc = this.prjBscInfoService.selectById(Long.valueOf(prjId));
            PrjPrdBscInfoVO prjPrdBsc = this.prjPrdBscInfoService.selectById(Long.valueOf(prjPrdId));
            if (null != prjPrdBsc.getGuidePc()) {
                prjPrdBsc.setGuidePc(DecimalUtils.convertFenToYuan(prjPrdBsc.getGuidePc().longValue()));
            }
            vo.setPrjBscInfo(prjBsc);
            vo.setPrjPrdBscInfo(prjPrdBsc);

            if (StringUtils.isNotBlank(prjPrdDtlId)) {
                PrjPrdDtlTkVO tk = this.prjPrdDtlTkService.selectById(Long.valueOf(prjPrdDtlId));
                PrjPrdDtlVO dtlVO = this.prjPrdDtlService.selectById(Long.valueOf(prjPrdDtlId));
                if (null != dtlVO) {
                    vo.setDtlVO(dtlVO);
                }
                if (null != tk) {
                    vo.setDtlTkVO(tk);
                }
            }

            if (CollectionUtils.isNotEmpty(vo.getPrjPrdPayDetailList())) {
                ListPageVO<PrjPrdPrpsFeeDetailVO> listPage = new ListPageVO<PrjPrdPrpsFeeDetailVO>(vo.getPrjPrdPayDetailList(), vo.getPrjPrdPayDetailList().size());
                vo.setPrjQuatPrpsPaySchPage(listPage);
            }
            if (CollectionUtils.isNotEmpty(vo.getFeeList())) {
                List<PrjPrdPaySchDVO> list = new ArrayList<PrjPrdPaySchDVO>();
                for (PrjPrdPaySchDVO prjPrdPaySchDVO : vo.getFeeList()) {
                    if (prjPrdPaySchDVO.getFeeClsCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_FEE_CLS_TYP_PRPS)) {
                        list.add(prjPrdPaySchDVO);
                    }
                }
                ListPageVO<PrjPrdPaySchDVO> listPage = new ListPageVO<PrjPrdPaySchDVO>(list, list.size());
                vo.setFeeDetailListPage(listPage);
            }
            result.setData(vo);
            BaseLogUtils.info(logger, "getMfrById", "获取PrjPrdPaySchM数据成功,ID:" + id, CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.info(logger, "getMfrById", "获取PrjPrdPaySchM数据失败,ID:" + id + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "getMfrById", "获取PrjPrdPaySchM数据失败,系统错误.ID:" + id + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName(), ex);
        }
        return result;
    }



    /**
     * 到车辆检测报告列表页面
     */
    @RequestMapping(value = "/toVehDetectionListPage.do", method = { RequestMethod.GET })
    public ModelAndView toVehDetectionListPage(HttpServletRequest request, HttpServletResponse response) {
        logger.info("加载VehDetection列表页面.");
        ModelAndView view = new ModelAndView("project/prjbscinfo/vehDetectionList");
        // 项目类型
        List<KeyValueVO> projectTypeList = this.prjBscInfoService.getProjectTypeList();
        // 业务类型
        List<KeyValueVO> bizTypeList = this.prjBscInfoService.getBizTypeList();

        view.addObject("projectTypeList", projectTypeList);
        view.addObject("bizTypeList", bizTypeList);
        return view;
    }


    /**
     * 初始化车辆检测报告列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initVehDetectionList.do", method = { RequestMethod.GET })
    @ResponseBody
    public Object initVehDetectionList(HttpServletRequest request,
                                       HttpServletResponse response) {
        String currentPage = request.getParameter("page");
        String pageSize = request.getParameter("pagesize");
        String cstNm = request.getParameter("cstNm");
        String prjTyCd = request.getParameter("prjTypCd");
        String bizTypCd = request.getParameter("bizTypCd");
        String paySchNo = request.getParameter("paySchNo");


        Pager page = new Pager();
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setCurrentPage(Integer.parseInt(currentPage));
        }
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setEveryPage(Integer.parseInt(pageSize));
        }

        PrjPrdPaySchMQueryCondition qc = new PrjPrdPaySchMQueryCondition();
        if (StringUtils.isNotBlank(cstNm)) {
            qc.setCstNm(cstNm);
        }
        if (StringUtils.isNotBlank(prjTyCd)) {
            qc.setPrjTypCd(prjTyCd);
        }
        if (StringUtils.isNotBlank(bizTypCd)) {
            qc.setBizTypCd(bizTypCd);
        }
        if (StringUtils.isNotBlank(paySchNo)) {
            qc.setPaySchNo(paySchNo);
        }
        qc.setPaySchTypCd(PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_WS);
        page.setCondition(qc);
        Pager pager = this.prjPrdPaySchMService.searchVehDetectionListPage(page);
        List<PrjPrdPaySchMVO> list = (List<PrjPrdPaySchMVO>) pager.getResultList();
        ListPageVO<PrjPrdPaySchMVO> listPage = new ListPageVO<PrjPrdPaySchMVO>(list, pager.getTotalCount());
        return listPage;
    }



    /**
     * 生成人保资料信息
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/addFileRec.do", method = {RequestMethod.POST})
    @ResponseBody
    public DataResultVO addFileRec(HttpServletRequest request, HttpServletResponse response) {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
        //String id = request.getParameter("id");//支付表ID
        String prjId = request.getParameter("prjId");//项目ID
        try {
            if (StringUtils.isNotBlank(prjId)) {
                result = this.prjPrdPaySchMService.addFileRec(Long.valueOf(prjId));
            }
            BaseLogUtils.info(logger, "addFileRec", "生成人保审核资料.[prjId=" + prjId + "]", CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "addFileRec", "生成人保审核资料.[prjId=" + prjId + "]" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "addFileRec", "生成人保审核资料.[prjId=" + prjId + "]" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }

    /**
     * 到退换车标签维护页面
     */
    @RequestMapping(value = "/toSiteTagTypeCdPage.do", method = { RequestMethod.GET,RequestMethod.POST })
    public ModelAndView toSiteTagTypeCdPage(HttpServletRequest request, HttpServletResponse response) {
        logger.info("加载toSiteTagTypeCdPage列表页面.");
        ModelAndView view = new ModelAndView("project/prjprdpayschtag/prjPrdPaySchTagPage");
        //支付表号
        String paySchNo = request.getParameter("paySchNo");
        //标记名称 reset-重置退换车标签,add-新增退换车标签
        String tagName = request.getParameter("tagName");
        //标签类型
        List<KeyValueVO> tagTypeCdList = this.sysDictionaryApiService.getKvListWithAttr1("PRJ0250", "1",CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
        //0-该支付表没有打标签.1-该支付表打了标签
        String tagFlag = "0"; //默认没打标签
        String tagTypeCd = "";
        String prePaySchNo = "";
        //通过支付表号查询是否有打标签记录
        PrjPrdPaySchTagQueryCondition queryCondition = new PrjPrdPaySchTagQueryCondition();
        queryCondition.setPaySchNo(paySchNo);
        queryCondition.setIsDel(0);
        List<PrjPrdPaySchTagDTO>  tagList = this.prjPrdPaySchTagApiService.searchPrjPrdPaySchTagList(queryCondition);
        if (CollectionUtils.isNotEmpty(tagList)) {
            PrjPrdPaySchTagDTO tagDto = tagList.get(0);
            tagTypeCd = tagDto.getTagTypeCd();
            prePaySchNo = tagDto.getPrePaySchNo();
            tagFlag = "1";
        }
        view.addObject("paySchNo", paySchNo);
        view.addObject("prePaySchNo", prePaySchNo);
        view.addObject("tagFlag", tagFlag);
        view.addObject("tagTypeCd", tagTypeCd);
        view.addObject("tagTypeCdList", tagTypeCdList);
        view.addObject("tagName",tagName);
        return view;
    }

    /**
     * 退换车业务打标签
     */
    @RequestMapping(value = "/siteTagTypeCd.do", method = { RequestMethod.POST })
    @ResponseBody
    public Object siteTagTypeCd(HttpServletRequest request, HttpServletResponse response)
            throws BaseException {
        BaseLogUtils.info(logger,"siteTagTypeCd","退换车业务打标签===");
        PrjPrdPaySchTagVO prjPrdPaySchTagVO = new PrjPrdPaySchTagVO();
        String paySchNo = request.getParameter("paySchNo");
        String prePaySchNo = request.getParameter("prePaySchNo");
        String tagTypeCd = request.getParameter("tagTypeCd");
        String tagName = request.getParameter("tagName");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES,"退换车业务打标签成功!");
        try {
            prjPrdPaySchTagVO.setTagTypeCd(tagTypeCd);
            prjPrdPaySchTagVO.setPaySchNo(paySchNo);
            prjPrdPaySchTagVO.setPrePaySchNo(prePaySchNo);
            prjPrdPaySchTagVO.setTagName(tagName);
            //当前用户ID
            prjPrdPaySchTagVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
            //操作时间
            prjPrdPaySchTagVO.setCrtTm(new Date());
            //调用后台,设置支付表标签
            BaseLogUtils.info(logger, "siteTagTypeCd", "请求参数,DATA:" + JSONObject.toJSONString(prjPrdPaySchTagVO));
            Long id = this.prjPrdPaySchMService.sitePaySchNoTag(prjPrdPaySchTagVO);
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.error(logger,"siteTagTypeCd","退换车业务打标签失败"+ ex.getMessage(),ex);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("新增失败!");
            BaseLogUtils.error(logger,"siteTagTypeCd","退换车业务打标签失败"+ ex.getMessage(),ex);
        }
        return result;
    }
}

